19. More kinds of methods


#1


The exercise:

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


It says:"Oops, try again. Your method failed when sideLength was 0 where it returned NaN instead of 0" I can't see where i'm 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

Try capitalizing length, so that you have:

return this.sideLength * this.sideLength;


#3

Ahhhh of course. Thanks!


#4

Simple mistake, but don't forget to add a value when you call your function then you will see math in action.


#5

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