18. Make your own method. Not sure where I have gone wrong



Can someone possibly point out where I have gone wrong with this code? I can't seem to find the solution, any help is greatly appreciated.

When I run the code the error message displays: Oops, try again. Make sure to set rectangle's width to 8!

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.setHeight = (6);
rectangle.setWidth = (8);


this lines:

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

setHeight (and then obviously also setWidth) are both methods (functions inside a object), which means you need to call them, not assign a value to them:

// method call


It's all good and working now. Appreciate the help!


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