More Kinds of Methods


It is printing
Oops, try again. Your method failed when sideLength was 0 where it returned NaN instead of 0.
// this is confusing me very much because I basically replicated the function before simply replacing the what it is returning using the same syntax. Maybe I'm overlooking something.


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



If you get NaN as a result of an operation then you're asking js to do something that doesn't make sense, doesn't result in a number (Not a Number)

So, have a look at how you got that value, where does it come from in your code?

If you're unsure what some variable refers to, keep in mind that you can just print it out.


ahh! i see where i went wrong. I didn't capitalize length in sidelength so i was trying to return using a variable that hadn't been defined. Thank you!


exactly the same mistake here :slight_smile: