4. I have to celebrate you baby


#1

var title = prompt("Movie");
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(title);

I can not seem to find the problem it looks perfect to me but it doesn't work.


#2

Hi this part

default
    return "I don't know!";
}

its missing the : after default


#3

I can't understand.
For starters a typed this:
"function getReview(name) {
switch (name) {
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!";
}
};"

And I had an error message after submitting my code: "Oops, try again. Better use a switch statement"
But I did use a switch statement!

Then I typed this:
"function getReview(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!";
}
};"

So, I've just renamed my variable. And no error messages, "Way to go!"
What's the problem?


#4

HI you forgot the break statemnt to each case

case '1':
    #do something
break;
case '2'
    #do something
break;

#5

Thank you for your answer, but it doesn't help me.
Actually, break statement is optional. In this particular case we have return statements and all code after return in each case branch will be unreachable. So there is no need to use break statements.

After all, even if you add break statements to my code there'll be the same bug:
despite using switch statement in code there will be an error message "Oops, try again. Better use a switch statement" after pushing the "Save & Submit" button.

function getReview(title) {
switch (title) {
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!";
}
};

And if you rename variable "title" to "movie" problem will be solved.

So, I see 2 problems.
1. Wrong error message (How can you tell me that i should use switch statement while i'm doing it right now? That's confusing)
2. Checking system is oddly preferes one variable name to another. That's confusing too. How can i guess what name is right and what name is wrong?


#6

There are some lesson in Javascript that are strict on the string for example if they give you that string

"Hello, I'm Mr.x"

and you write

"Hello , I'm Mr.x "

it'll see it an error.
So it's the same for that lesson they gave you that code when you begin

var getReview = function (movie) {

};

the lesson aspect you to use exatly that one if you change something it see it like an error.


#7

Thank you i feel like a idiot