Make Your Own Method


#1

I can't solve what's wrong.
"Oops, try again. It looks like you have an error in your code. Here's the message: ReferenceError: 'setWidth' no está definido "

var rectangle = new Object();
rectangle.height = 3;
rectangle.width = 4;
// here is our method to set the height
rectangle.setHeight = function (newHeight) {
  this.height = newHeight;
};
// help by finishing this method
rectangle.setWidth = function (newWidth) {
    this.width = newWidth;
};
rectangle.width = setWidth;
rectangle.height = setHeight;
// here change the width to 8 and height to 6 using our new methods
rectangle.setWidth(8);
rectangle.setHeight(6);


#2

could you explain this two lines:

rectangle.width = setWidth;
rectangle.height = setHeight;

why did you code it like this? Personally, i would remove them


#3

is that the problem
..i remove them but it still wont run


#4

its the problem in datasolver66743 code, doesn't mean its the same for you. Please go here and make a new topic if you have a question, otherwise we clutter this topic.


#5

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