# 19. More Kinds of Methods

#1

Hello, there,

I am stuck in this lesson. The computer display me this error:

Oops, try again. Your method failed when sideLength was 0 where it returned NaN instead of 0.

Could you help me? I do not know what is wrong. Thank you very much.

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.sideLenght * this.sideLenght;
};

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

#2

You've mixed up your varibles somewhere, or otherwise made an operation that doesn't make sense, which is why you get Not a Number value as your result

``````> 1 + undefined
NaN
> Infinity - Infinity
NaN``````

#3

But how did I do that? That is the whole code that I posted in the first post.?

#4

Doesn't really matter how you did it. What matters is what you should do. So you would first make sure that you have a firm idea of what it should be doing all the way through, and then start observing what it does do. How can you observe what it does? Just print out partial results. Start somewhere in the middle of the process and check if the situation is still sane or not, and then go earlier or later in the process based on that result, repeat until you've narrowed it down to the non-sensical action.

#5

you wrote "Lenght" instead of "Length" when returning area function

#6

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