I have to celebrate you baby



I'm trying to make this work with a loop function but, I'm always getting "else" option. Any ideas what the problem is? Thanks.

var movies=new Object()
    name: "Toy Story 2",
    review: "Great story. Mean prospector."

    name: "Finding Nemo",
    review: "Cool animation, and funny turtles."

    name: "The Lion King",
    review: "Great songs."

var getReview = function (movie) {
    for(var x in movies){
        if(movie===movies[x].name){return movies[x].review}
            else {return "I don't know!"}

getReview("Finding Nemo")


a function ends the moment a return keyword is reached

your loop either finds the first movie, or it returns i don't know. You should place return it don't know outside the for loop so the whole loop can run

your loop only makes one iteration, since in the first iteration a return keyword is reached which breaks the loop


That makes sense. I did not even know that if function reaches it's first return case, it's stops. Now it's all working though, the site is still asking for the switch version to go through. Thanks alot!