Number 18 make your own method


So I followed the instructions and came up with this code

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

and it keeps giving me errors. any idea what i'm doing wrong? thanks!


This is a cute error because it shows the problem with the lesson itself. The entire lesson is having you create these properties through assigning them rather than declaring them upfront, and so conditioned you to create this very simple and understandable mistake.

I am sure you know how a function works, but you instead called the method again using = signs when you should have just wrote them normally

// Do This

// Not This
object.method = (parameter)