Case 1 always shows up


#1

no clue why case 1 always printed out with the correct answer


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");
break;
}
};


#2

you need to call the function in order for the function to execute? That there is any output at all is very likely caused by the exercise validating your code with case Toy Story 2


#3

called the function actually, but it shows the correct answer with "Great story. Mean prospector." shows in the second line.

I wrote 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");
break;
}
};

getReview("The Lion King");

the result shows


Great songs.
Great story. Mean prospector.

error message

Oops, try again. Are you sure you're returning the right thing?


#4

your function doesn't return anything? It only logs to the console


#5

If I write 'return function(movie); I get an error code of: unexpected token.
I do not obviously totally understand your point. Please explain further.


#6

can i see an updated version of your code?


#7

'];
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!");
console.log function (movie);
}
};



#8

for example for toy story 2, you still log the review to the console, you don't return the review ("Great story. Mean prospector.")


#9

The first line of my code did not

'];
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!");
console.log function (movie);
}
};

The first line of my code did copy.


#10

I change the last line to:
1) return getReview;
2) return getReview(movie);

Both still return the Toy Story review. Thoughts.


#11

this is the review for toy story 2:

"Great story. Mean prospector."

which you log the console, you should return review.


#12

I changed the code to - return review - and again got the review for Toy Story 2.
The error message is always the same - Are you sure you are returning the right thng.


#13

I think what he means is instead of using console.log() you should be using return. For example, instead of

console.log("Great story. Mean prospector")

use

return "Great story. Mean prospector"


#14

Replace all your console.log() and use return keyword to return statement.


#15

Thank you, that suggestion solved it. I was not getting the full impact of his reply.


#16

Hello @edway5409

In your code, You need to delete all of your console.log() and use return like this..

case "Toy Story 2":
return "Great story. Mean prospector.";

also you dont need break keyword ,return will be suffice..
Do this to all of the code lines and tell what are you getting ?


#17

Model to follow...

var getReview = function (movie) {
    switch (movie) {
    case "Toy Story 2": return "Great story. Mean prospector.";
    // ...
    }
};

console.log(getReview("Toy Story 2"));

#18

I made the changes suggested and it worked well.
Thanks for all the help. I am very dense today.


#19

We all have days like that. Shake it off and be easy on yourself. Go for a quick walk or step away from your work and do something else for a while. Our brain works best when we give it time to sift through a problem.


#20

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