Make your own method


#1

https://www.codecademy.com/en/courses/spencer-sandbox/2/6?curriculum_id=506324b3a7dffd00020bf661

var rectangle = new Object();
rectangle.height = 3;
rectangle.width = 4;
// here is our method to set the height

 

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


rectangle.setWidth(8);
rectangle.setHeight = function (newHeight) {
  this.height = newHeight;
};
 

rectangle.setHeight=setHeight;
rectangle.setHeight(6);

ReferenceError: setWidth is not defined

What is wrong?


#2

Remove these two lines

and


#3

Also you have error here:

rectangle.setWidth= function(newWidth){
    this.Width = newWidth; // should be this.width
};

#4

Спасибо!:)Не знаю как я это пропустила)


#5

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