Keep getting UNDEFINED error


#1

var movies = {}

movies.toystory = {
name: "Toy Story 2",
review: "- Great story. Mean prospector."
}

movies.findingnemo = {
name: "Finding Nemo",
review: "- Cool animation, and funny turtles."
}

movies.thelionking = {
name: "The Lion King",
review: "- Great songs."
}

var findReview = function(movie) {
for (var i in movies) {
if (movies[i].name === movie) {
return movies[i].review
}
}
}

var getReview = function(input) {

switch (input) {
case "Finding Nemo":
findReview(input)
break;

case "Toy Story 2":
  findReview(input)
  break;

case "The Lion King":
  findReview(input)
  break;

default:
  return ("I don't know!")
  break;

}
}

console.log(getReview(prompt("Type movie to get review!")))

RESULTS:

undefined

what is wrong ?


#2

Alright, I believe this is your problem. Functions only can be called once per line, You can assign variables to values and use those values, however there can only be One function call per line.

var example = prompt("Type move to get review!");
var example2 = getReview(example);
console.log(example2);

Or you could just put a console.log statement in each of your cases. Either way that's where your error is coming from.


#3

I replaced console.log(getReview(prompt("Type movie to get review!")))

with what you wrote . Same result.

I finally broke down the code in a much simpler way just to proceed to next lesson .


#4

Simple is best when you're trying to pass these lessons, the console looks for specific things in your code and will fail you if it isn't met.