19. More kind of methods


#1

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();

Question

What wrong in this code?


#2

Your object has only one attribute called sideLength.

Problem is in your calcArea method. Value of this.sidelength is simply undefined.

Remember that JavaScript is case sensitive.

sideLength
sidelength

Do you see a problem now? :smile:


#3

Hey @digitalplayer55798! First off try to organize your code by selecting over it and hitting CTRL + K on your keyboard. Secondly the simple problem is that

when you initalized it you made it camel CASE whitch is what your suppose to do

Here:

But then when you called it in the Calc Area you didnt camel case that. Just camel Case that:

Hope it helped if it didnt! Pls resopond saying so!


#4

Thanks Buddy! :grin: I will double check my code here after!


#5

Thanks, funny I did the same mistake :sweat: