18.Make your own method


#1

what is wrong in my code-

var rectangle = new Object();
rectangle.height = 3;
rectangle.width = 4;

rectangle.setHeight = function (newHeight) {
this.height = newHeight;
};

rectangle.setWidth =function(newWidth){
this.width=newWidth;
};

rectangle.setHeight=setHeight;
rectangle.setHeight(6);
rectangle.setWidth=setWidth;
rectangle.setWidth(8);


#2

Problem.
You have to call methods setHeight and setWidth on rectangle object and pass them arguments (and you did but added these extra lines of code?)

rectangle.setHeight=setHeight;

rectangle.setWidth=setWidth;

you don't need them!


#3

rectangle.setWidth =function(newWidth){
this.width=newWidth;
};

should be :
var setWidth = function (new Width){
this width = newWidth};

the original codei it provided was wrong


#4

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.