4. I have to celebrate you baby


#1

Okay, so I just had to ask here to get some clarification.

This below is my code:

var toyStoryTwo = {
    name: "Toy Story 2",
    review: "Great Story. Mean prospector."
};

var findingNemo = {
    name: "Finding Nemo",
    review: "Cool animation, and funny turtles."
};

var theLionKing = {
    name: "The Lion King",
    review: "Great songs."
};

var getReview = function (movie) {
    switch (movie) {
        case "Toy Story 2":
            return toyStoryTwo.review;
        case "Finding Nemo":
            return "Cool animation, and funny turtles.";
        case "The Lion King":
            return theLionKing.review;
        default:
            return "I don't know!";
    }
};

var user = prompt("Coose a movie!");

getReview(user);

So this code eventually worked, but can swear that it didn't for the longest time, but simply said "Is it returning the right thing?"

I changed it and changed it back a bunch of times, as you can see, I even tried different ways of how to return exactly what.
Eventually it just worked.

Is this a CC bug of some sort?
Can it have been something else?
Because I tried to rewrite it in some of the ways that didn't work from the start, and now they work too.

It would be good to know if sometimes you need to restart the browser or something(which I have tried on some occasions), because it feels as it has happened before, and it is obviously confusing when trying to learn, because you start to think that what you have learned doesn't work, and you start to second guess whether you understand what you think you do.

Answer would be very appreciated, thanks!


#2

You didn't have write ANY properties in this level.

All you had to do was put a case of the movie name(like this):

 case "Toy Story 2":

and return the review, like this:

return"Great story. Mean prospector.";

It may have not worked because you returned a property of the movie, making it return the wrong thing(maybe). Here's my code. As you can see, you did not have to do anything complicated.

var getReview = function (movie) {
    switch(movie){
        case "Toy Story 2":
            return"Great story. Mean prospector.";
            break;
        case "Finding Nemo":
            return"Cool animation, and funny turtles.";
            break;
        case "The Lion King":
            return"Great songs.";
            break;
        default:
        return"I don't know!";
    }

};

#3

You also forgot break in your switch statements. Basically the part above your function is unnecessary.


#4

The part above I just did because I wanted to see if it was possible to implement.
Are you sure about the breaks in switch?
Because I thought about having them initially, but then I thought it wouldn't work since the function is returning something before it can even break.
Or is it possible for a function to first return, and then break afterwards?


#5

It's just good practice to have the break; in place in case the script messes up or you forget a ; or something.


#6

I don't think you have to use a break in a switch statement IF it is a return statement. You have to do it if it has like if statements and console.logs, but it's a good habit to do it. More organized. :smiley:


#7

Note: it will work without break parts too.


#9

var user = prompt("Choose a movie!");