getReview - function: Expects "Switch" .. wouldn't "for .. in" be better?


#1

I don't know why, but in the task "I have to celebrate you baby" i should use a switch to find a movie title in an object. But i'd prefer to find the right object by the "for .. in", because i don't want to type 100 cases, if my movie/review-object contains 100 movies. So : What is wrong with my solution? Why does the program forces me to use a switch?

var getReview = function (movie) {
    for(var key in movieCollection) {
        if(movieCollection[key].name === movie) {
            return movieCollection[key].review;
        }
    }
};

#2

a loop would make more sense, but sometimes the lesson teaches you a way of achieving something, which you have to use in order to pass


#3

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