What is wrong in my code? Objects I, ex 4


#1

I have checked my code in both JSHint and JSLint - both report the code as clean, yet I can't get past this exercise?

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


#2

function getReview(movie) would be the correct way to write the first part of the code down. Therefore, you do not need to write var movie nor use strict. Also, at the end of every case, you must put a break;

Hope it helped!:smiley:


#3

good call. the variable definition and use strict were both tips from JSLint. Also, does the return string need to be inside parens? ()

// now finished the exercise. thank you ragezapper!


#4

@ragezapper,
-1
if the return-statement is used in a case
a break is NOT needed, as it is the return-statement which will cause the =exit= from the switch

-2
concerning the named function or anonymous function via a VARIABLE
here an article
http://stackoverflow.com/questions/336859/var-functionname-function-vs-function-functionname?rq=1


#5

Oh.. really? Never knew that :smiley:. Learning everyday, thanks.