Question in I have to celebrate you baby


#1


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


First, i want check if my code has any problem although the page shows it's correct.

the problem is that why the screen doesn't show any print/I can't see any output on the upright screen , no matter i use "console.log" or "return". why??

and i find, sometimes, both console.log and return will print out on the screen, while sometimes only console.log..why??

and do we need do use ( ) after return.
actually the course doesn't introduce much about return. so I have some confusion.

var films = {
    ToyStory2: {
        name: "Toy Story 2",
        review: "Great story. Mean prospector."
    },
    FindingNemo: {
        name: "Finding Nemo",
        review: "Cool animation, and funny turtles."
    },
    TheLionKing: {
        name: "The Lion King",
        review: "Great songs."
    }
};

var movie = prompt ("What film do you want to search", "Please notice the capitalization and space.");

var getReview = function (movie) {
    switch (movie) {
        case "Toy Story 2":
            console.log ( films[ToyStory2].review);
            break;
        case "Finding Nemo":
            console.log ( films[FindingNemo].review);
            break;
        case "The Lion King":
            console.log ( films[TheLionKing].review);
            break;
        default:
            console.log( "I don't know!");
            break;
    }
   
};


#2

films is an object, not an array. So, should be:

console.log (films.ToyStory2.review);

Also you can use object's properties instead of strings:

var getReview = function (movie) {
    switch (movie) {
        case films.ToyStory2.name:
            console.log (films.ToyStory2.review);
            break;
        ...
    }
};

Syntax:
return value;

So, we don't need to use ()

NOTE
You don't need to use prompt(), just call your function:

getReview( "Toy Story 2" );

#3

If you use getReview, you don't may to write "case films.ToyStory2.name:" in switch struct. I trying ) With love from SPb.


#4

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