Make Your Own Method issues


#1

I need some help. When I save and submit, it gives me the error:

Oops, try again. It looks like you have an error in your code. Here's the message: TypeError: rectangle.newWidth is not a function.

Can anyone find the problem?

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;
};

// here change the width to 8 and height to 6 using our new methods
rectangle.newWidth(8);
rectangle.newHeight(6);

#2

here you call the methods, for this you should the method names (setHeight and setWidth)


#3

I did that, and it just changed the error message to:

Oops, try again. It looks like you have an error in your code. Here's the message: ReferenceError: setWidth is not defined

I have tried other things, like setHeight(6);, rectangle.setHeight(6);, rectangle.newHeight(6); :unamused:


#4

it should then of course be rectangle.setWidth(8), given setWidth is a method of rectangle object.

If you still have problems afterwards, post an updated version of your code and exercise url


#5

Wow, thanks. That was too obvious.


#6

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