18.Make Your Own Method in 13 Introduction do objects


#1

Well, guys I don't get find my mistake, could you help me?

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

// help by finishing this method
rectangle.setHeight = setHeight;
rectangle.setWidth = setWidth;

// here change the width to 8 and height to 6 using our new methods
rectangle.setHeight(6);
rectangle.setWidth(8);

ReferenceError: setHeight is not defined


#2

This part is not needed

// help by finishing this method
rectangle.setHeight = setHeight; 
rectangle.setWidth = setWidth;

You can erase it. It's causing trouble because setHeight represents nothing.


#3

Oh, yeah!

thank you now it runs!


#4

Thank you!

I refused to click the 'hint or Q/A' option for a while, but I wasn't able to make this particular exercise work due to this reference error. No I finaly made it run.
What I do not understand is, and I don't want to make this question look any redundant, why we had to 'setAge' in previous practice and in this 'rectangle' exercise we don't have to.

If you have any feedback as spot on as always, please advise :wink: Thank you!


#5

Hi @reinierburgering, I am glad I helped you.
As for your other question, I will review both exercises to see what you mean and explain why it was important to have 'setAge' in the previous practice. :slight_smile: