Make Your Own Method


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


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


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


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