I have to celebrate you baby


#1

https://www.codecademy.com/courses/spencer-sandbox/0/4?curriculum_id=506324b3a7dffd00020bf661#


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()
movies.toyStory={
    name: "Toy Story 2",
    review: "Great story. Mean prospector."
}

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

movies.king={
    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")


#2

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


#3

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!


#4