24. Objects with Methods (NaN error)


#1

Hi folks,

This has been resolved!! Found my typo only seconds after posting!! height was missing a t !!
Thanks, and if you're getting the same NaN maybe you can look for a similar typo.

Cheers

Code below appears close but just not cutting it for CodeCademy and so I'm getting an error message that reads "According to your code, a rectangle with sides 1 and 1 has a perimeter of NaN when it should be 4".

Code here:
function Rectangle(height, width) {
this.height = height;
this.width = width;
this.calcArea = function() {
return this.height * this.width;
};
// put our perimeter function here!
this.calcPerimeter = function(){
return this.heigh * 2 + this.width * 2;
};
}

var rex = new Rectangle(7,3);
var area = rex.calcArea();
var perimeter = rex.calcPerimeter();

Can anybody tell what is wrong with my code to return NaN?
Thanks for any feedback!

Alex


#2

return 2 * height + 2 * width;
};


#3

something is wrong here. i've written in

return 2 * this.heigth + 2 * this.width;

and it gave a NaN error message.

than i tried with: return (2 * this.heigth + 2 * this.width);

NaN error again.

than i copied the same line from an answer and it turned out to be working.

still dont understand.


#4

Check your spelling of height.


#5

omg, checked it 15 times. :DDD thanks! :smiley:


#6

Yo tenia el mismo error el de NaN, pero encontre por que era el error. Aqui esta el codigo correcto:
function Rectangle(height, width) {
this.height = height;
this.width = width;
this.calcArea = function() {
return this.height * this.width;
};
// put our perimeter function here!
this.calcPerimeter = function(){
return 2 * height + 2 * width;
}
}

var rex = new Rectangle(7,3);
var area = rex.calcArea();
var perimeter = rex.calcPerimeter();

Donde uno deberia poner return this.heigth * 2 + this.width * 2, hay que poner return 2 * height + 2 * width