Any one know why this won't break, and keeps going to default


#1

var getReview = function (movie) {

switch(movie){
    case 'TOY STORY 2':
        console.log("Great story. Mean prospector.");
        break;
    case 'FINDING NEMO':
        console.log("Cool animation, and funny turtles.");
        break;
    case 'THE LION KING':
        console.log("Great songs.");
        break;
    default:
    console.log("I don't know that");       }
};

var review = prompt("Which movie are you interested in a review? ").toUpperCase();
getReview(review);


#2

Well depending on how you have it there's a couple thing that could be wrong. First of all note that the "case"s are Case Sensitive. meaning if there's any letters that are not capitalized or letters that aren't perfectly matching, it will automatically move to the default case.

Make sure that whatever is in the Variable that matches exactly to what's in the case statement.


#3

Even if i type the wrong question and it go's straight to the default statement, in the console window it gives me a "i don't know that" twice in a row like its looping or something weird.


#4

I took a look at it... it seems really strange.
I feel like it's some kind of really technical thing, or possibly even a bug. It's only a couple of lines, and I couldn't figure it out in 15 minutes.

Not totally sure what it is, but you could just use an if/else if/else instead.


#5

Hey @bluntslide,

You got some prolems there. :smiley:

Actually, one problem.

WHAT ARE THOSE?!(Sorry I had to put that. :smile:)

You see the ".toUpperCase();" part? If you put Toy Story 2, that makes TOY STORY 2. Which doesn't match! That's why it goes to default automatically. IT DOESN'T MATCH! :smiley:


#6

But, his case in the switch statement is "TOY STORY 2", and it prints out BOTH "Great story. Mean prospector." AND "I don't know that."


#8

var getReview = function (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:
        console.log("I don't know");
}

};
var movie=prompt("enter movie name");
getReview(movie);
try passing movie in your review function other than review and change case to " " double quotes @bluntslide
you have to enter movie name as same as given in instruction if u dont use .toUpperCase( ); or .toLowerCase( ); :smile: