Make Your Own Method (already drives me crazy)


#1

already feel like it;s website bugged or smth
can somone tell me why it happens?
it runs logs 6 8
for height and width
works fine but writes that error below
pls somone help me

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

Oops, try again. Make sure to set rectangle's width to 8!

//created object rectangle
var rectangle = new Object();

//filled with height width
rectangle.height = 4;
rectangle.width = 3;

//created setHeight method
var setHeight = function (newHeight) {
  this.height = newHeight;
};

//created setWidth method
var setWidth = function (newWidth) {
  this.width = newWidth;  
};
 
  rectangle.setheight = setHeight;
  rectangle.setwidth = setWidth;

// here changed the width to 8 and height to 6 using our methods
rectangle.setthatfkingheight(6);
rectangle.setthatfkingwidth(8);

//than loged 
console.log(rectangle.height);
console.log(rectangle.width);

result was 
6
8

#2

Instead of:

rectangle.setheight = setHeight;
rectangle.setwidth = setWidth;

should be:

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

Where did you declare functions setthatfkingheight and setthatfkingwidth?


#3

maybe in rectangle.setthatfkingheight(6); i needed have only setheight(6) ?

but thanks for reply maybe passed it :cold_sweat:


#4

You need setheight(6) and setWidth(8). To call these function:

rectangle.setheight(6);
rectangle.setwidth(8);

#5

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