4. I have to celebrate your baby


#1

what is wrong with my code

var name = prompt("Toy Story 2, Finding Nemo, or Lion King");

if(name === "Toy Story 2") {
    return "Great story. Mean prospector.";
} else if(name === "Finding Nemo") {
    return "Cool animation, and funny turtles.";
} else if(name === "Lion King") {
    return "Great songs.";
} else {
    return "I don't know";
}

#2

I thought you were supposed to use a switch statement, also you cannot return outside of a function.


#3

ok, I changed it, but there is still an error.

var answer = prompt("Toy Story 2, Finding Nemo, or Lion King");

var getReview = function (movie) {
switch(movie){
case "Toy Story2":
return "Great story. Mean prospector.";
break;

  case "Finding Nemo":
      return "Cool animation, and funny turtles.";
      break;

  case "Lion King":
      return "Great songs.";
      break;

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

};
getReview(answer);


#4

Should be a space between Story and 2.


#5

It still gives an error, it says;

Oops, try again. Check the review of The Lion King


#6

Paste in the exact quote.


#7

What quote are you talking about?


#8

It needs to be "The Lion King" not "Lion King"


#9

It worked!!! thanks man


#10

I am confused, his var is answer, and his function is taking in (movie) shouldn't the var be movie?


#11

No he has it right, what his getReview(answer) is doing is taking the user's answer from the prompt as it's value then it gets saved to the variable answer.

Then when he calls answer again it will whatever was inputed into the prompt.

So if he put Lion King in the prompt it would return

getReview(answer) // answer storing the words Lion King which would then return Great Songs.

Let me know if you want this clarified more simply


#12

whats wrong in this code? Its showing unexected token.

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);


#13

After case it's not a semi-colon try something else thats very similar


#14

// Try This works Cool !!! :sunglasses:

var answer=prompt("enter the name of the movie to get the review");
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!";
break;
}
};
getReview(answer);


#15

This is confusing they should mention that it should require to have commas and periods..


#16

Here's my code:

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

return review;

}


#17

while using the switch function after allotting the case, you cannot sign a variable a certain value. You can only log things to the console. So the correct version is this:

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!");
}
};
getReview();

And don't forget that you should not add break while default.
just let me know if the correction sent doesn't work.


#18

Solution utilizing a "movieList" object. Alas, the solution is rejected. :frowning:

var getReview = function (movie) {
    for(var mov in movieList)
    {
        if(movie === mov)
        {
            return(movieList[mov].review);
        }
    }
    return("I don't know!");
};

var movieList = {
    "Toy Story 2":{
        name: "Toy Story 2",
        review: "Great story. Mean prospector."
    },
    "Finding Nemo":{
        name: "Finding Nemo",
        review: "Cool animation, and funny turtles."
    },
    "The Lion King":{
        name: "The Lion King",
        review: "Great songs."
    }
};

console.log(getReview("Finding Nemo"));

#19

How it worked what does mean by to put it within the exact quotes


#20

Just incase anyone needs the answer.

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:
return "I don't know!";
}
};
getReview("Toy Story 2");

Its just simple spelling stuff that makes it shown as incorrect.