19 More Kinds of Methods


#1

Hi can someone please help me out with this?
Instruction says to make second function as first one...

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.sideLength;
};

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

and in response I have: "Your method failed when sideLength was 0 where it returned NaN instead of 0"

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

square.calcArea = function() {
if( this.sideLength != 0;) {
return this.sideLenght * this.sideLength;
};
else { return 0; };
};

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

it didn't helped either... Please can someone give me a hint what am I doing wrong here
(except believing that I ever be able to write code on my own...)


#2

What happens after you fix this typo?


#3

The same : I get response


#4

You haven't fixed the typo I pointed out.


#5

Ok I got it.
Thank you.
English is not my first language.

Gentelman.