19. More kinds of methods


#1

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

Error: Unexpected token ,

Code:

var square = new Object();
square.sideLength = 6;
square.calcPerimeter = function() {
  return this.sideLength * 4;
};
// help us define an area method here
var square.calcArea = function() {
    return this.sideLenth * this.sideLength;
};
var p = square.calcPerimeter();
var a = square.calcArea();

#2

Your code shouldn't throw that error @feephill. Just try it again and see what happens.

Regards,
Barry Allen


#3

You shouldn't use var keyword here.

square.calcArea = function() {...}

#4

Okay, I did that. Now it's still throwing me the same error. :confused:


#5

I've already been doing that for awhile now just looking for the error. Thanks anyway though, defeat Dr. Wells safely!


#6

Here, you mispelled Length you wrote Lenth.

Your code should work after correcting that :grin:


#7

Thanks, it works now.


#8

You're super welcome! :grin:

If that was the answer you were looking for feel free to click the solution button below my reply. :smile:


#9

it should be

square.calcArea = function(){...};

and not

var square.calcArea = function(){...};

#10

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