Make Your Own Method


#1


Make Your Own Method


I keep getting an error message stating TypeError: rectangle.newHeight is not a function, despite the fact that this is the part of the code that was provided for us. Can anyone see what's going wrong?


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.newHeight(6);
rectangle.newWidth(8);


#2

As it says, no such method. Which methods have been created for that object? Tip: print out the object


#3

setWidth and setHeight not newHeight and newWidth. Got it. Thank you!


#4

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