More kinds of Methods


#1

Whats wrong with my code.
The error tells me that "Oops, try again. Your method failed when sideLength was 0 where it returned NaN instead of 0"

var square = new Object();
square.sideLength = 6;
square.calcPerimeter = function() {
return this.sideLength * 4;
};
square.calcArea = function() {
return this.sidelength * this.sidelength;
};

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


#2

Hi here

return this.sidelength * this.sidelength;

You should use this.sideLength instead of this.sidelength


#3

Thank you, It worked


#4

I stucked in Introduction to objects section 13 chapter function reveiw.
can any one help, wats wrong in my code

var square = function (x) {
return x * x;
};

var mulitply = function(x,y) {// Write the function multiply below
return x * y;
};// It should take two parameters and return the product
multiply(x);


#5

HI when you call the function multiply you should put two number inside it

//It should take two parameters and return the product

multiply()

then here

var mulitply = function(x,y)

you wrote mulitply instead of multiply


#6

Thank you so much sir, i have seen all the topics in all chapter, for all problem u solve it nicely.


#7

Can you tell me what is wrong in this code? i'm getting SyntaxError: Unexpected token return

var answer = prompt("Toy Story 2,Finding Nemo,or The Lion King")
var getReview = function (movie) {

switch (movie) {
case "Toy Story 2",
return "Great story.Mean prospector.";
break;
case "Finding Nemo",
return "Cool animation, and funny turtles.";
break;
case "The Lion King",
return "Great songs.";
break;
default:
return "I don't know!.",
}
};
getReview(answer)


#8

Hi your case condition should end with a : like that ..

case "Toy Story 2":
.....
case "Finding Nemo":
...

#9

Still its showing warning like this Oops, try again. Check the review of Toy Story 2
but i'm getting output.


#10

you should copy the exacte review they gave in the lesson

Edit:
I didn't notice that but next time it's better if you create a new topic..


#11

Ya i got it thank you so much