Why does it say NaN?


#1



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


When I run this code, it tell me: "Oops, try again. Your method failed when sideLength was 0 where it returned NaN instead of 0," but I don't understand what I'm doing wrong!


var square = new Object();
square.sideLength = 6;
square.calcPerimeter = function() {
  return this.sideLength * 4;
};
// help us define an area method here
square.calcArea = function() {
    return this.sidelength*this.sidelength
};
var p = square.calcPerimeter();
var a = square.calcArea();


#2

It says NaN (Aka Not a Number) because you accidentally used:

And forgot to capitalize the L in sideLength. The other one (lowercase) is undefined, and won't be a number. :slight_smile:


#3

True the correct thing many learners are forgetting is to put L is caps in sideLength instead learners are typing it in small case. Good Luck!


#4

Just for reference, the correct code:

var square = new Object();
square.sideLength = 6;
square.calcPerimeter = function() {
return this.sideLength * 4;
};
// help us define an area method here
square.calcArea = function() {
return this.sideLength * this.sideLength;
};

var p = square.calcPerimeter(2);
var a = square.calcArea(4);