I have to celebrate you baby-Bug?


#1

I think This is Bug . Am i right ?

It says You better use switch statement

var getReview = function (movie) {
var answer=prompt('Your movie ?')
switch (answer){
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")
break;
}
}; 
getReview();

#2

Try return instead of console.log, and prompting the user is extra for passing through this exercise.

Here's my code for reference;

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;

 default:
    return "Great soundtrack I think."

}
};


#3

yeah i know but i wanted to modernize my program i added prompt so i would choose movie :slight_smile:


#5

I tried this and it worked:

var answer = prompt("What movie do you want to search?").toUpperCase();

var getReview = function (movie) {
   switch(answer) {
   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();



I also tried with arrays and I found it was easier to read:

var request = prompt("What movie do you search?").toUpperCase();
var title = ["TOY STORY 2", 
             "FINDING NEMO", 
             "THE LION KING"
            ];
var review =["Great story. Mean prospector.", 
             "Cool animation, and funny turtles.", 
             "Great songs."
            ];

var getReview = function (movie){
  switch(request){
  case title[0]:
    console.log(review[0]);
    break;
  case title[1]:
    console.log(review[1]);
    break;
  case title[2]:
    console.log(review[2]);
    break;
  default:
    console.log("I don't know!");
  }
};

#6

Ive done it this way as you have, and i get the error code try using a switch statement. it returns the correct review as requested. i must be making a simple mistake somewhere. Here is my code:

var getReview = function (movie) {

var answer = prompt("What movie are you curious about?").toUpperCase();

switch(answer){
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(movie);


#7

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('Finding Nemo');

//returns "Cool animation, and funny turtles."

For anyone having trouble with return statements.


#8

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.