Intro to objects: make your own method


#1

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

rectangle.setWidth = function (newWidth) {
this.width = newWidth;
};

rectangle.setWidth = setWidth;
rectangle.setHeight = setHeight;

setWidth(8)
setHeight(6)

For some reason the setWidth is not being defined.. I don't know what I did wrong


#2

The above lines are an attempt to assign an undefined object to an already defined variable. Both lines may be removed.

Again, these lines refer to undefined objects. Should be,

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