Reputation: 42069
I'm working on a JavaScript tutorial at codecademy.com
It starts by giving you the following outline for a function
var getReview = function (movie) {
};
Then it gives you a list of movies, and it tells you to write a function so that it returns a review for a movie based on whatever movie was passed in as a parameter. The question also suggests that you use a switch statement. Below is what I came up with but it's not the correct answer. Codecademy doesn't unfortunately reveal the answer. I thought it was weird to put a switch statement in a function, but that's what it said had to be done.
Can anyone explain what I did wrong?
var getReview = function(movie) {
var result;
switch (movie) {
case "Matrix":
result = "good trip out";
break;
case "Princess Bride":
result = "awesome date night movie";
break;
case "Welcome to America":
result = "Amjad's favorite";
break;
case "Remember the Titans":
result = "love the sports";
break;
case "Why do I look like I'm 12?":
result = "The Ryan and Zach story"
break;
case "Fighting Kangaroos in the wild";
result = "Token Australian movie for Leng"
break;
default:
result = "I don't know";
}
return result;
};
Upvotes: 0
Views: 467
Reputation: 34608
case "Fighting Kangaroos in the wild";
Should be a colon, not a semi-colon.
Also a few semi-colons missing after the lines that assign to result
.
Since a function is a reusable block of code - any code - a switch statement is perfectly legitimate inside one. In this case it's necessary because the function needs to compare the passed movie
against a list of possible cases.
p.s. if you're new to JS, get into the habit of good indentation, too :) It'll stand you in good stead.
Upvotes: 1