4. I have to celebrate you baby


#1


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


Oops, try again. There was a problem with your syntax.


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


#2

@bibleman13 are you available??? :smiley:


#3

Syntax

switch(expression) {
    case n:
        code block
        break;
    case n:
        code block
        break;
    default:
        code block
}

So you have wrong switch syntax

var getReview = function (movie) {
    switch(movie) {
        case "Toy Story 2":
            return "Great story. Mean prospector." // should be ; at the end
            break: // should be ; instead
    switch(movie) { // remove it 
        case "Finding Nemo":
            return "Cool animation, and funny turtles." // should be ; at the end
            break: // should be ; instead
    switch(movie) { // remove it
        case "The Lion King" :
            return "Great songs." // should be ; at the end
            break: // should be ; instead
    }
    } // remove it
    } // remove it
};

This is how it works:

  1. The switch expression (movie) is evaluated once.
  2. The value of the expression (movie) is compared with the values of each case ("Toy Story 2", "Finding Nemo", "The Lion King").
  3. If there is a match, the associated block of code is executed.

#4

Sorry I wasn't! I have been packing my bedroom and other bedrooms all day! In fact, this is the first time I have logged on to my computer all day. But @denys.matsevych has got your back with a great explanation :smiley: thanks man!


#5

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