3. Literally Speaking


#1

https://www.codecademy.com/courses/objects-ii/0/3?curriculum_id=506324b3a7dffd00020bf661#

When I run my code I receive the following errors:

Oops, try again. There was a problem with your syntax.
SyntaxError: Unexpected Token

Unfortunately, if there is a syntax error in my code, I have no idea where it is located.

var james = {
    job: "programmer",
    married: false,
    speak: function (mood) {
        switch(mood) {
            case "great":
                console.log("Hello, I am feeling great");
                break;
            case "just okay":
                console.log("Hello, I am feeling just okay");
                break;
            default:
                break;
        };
    };
};

james.speak("great");
james.speak("just okay");

#2

 default:
                break;
        }; // unnecessary semi-colon 
    };  // unnecessary semi-colon

why do you even have a switch statement?


#3

That worked, thanks! Here is my updated code:

var james = {
    job: "programmer",
    married: false,
    speak: function(mood) {
        if (mood == "great") {
            console.log("Hello, I am feeling great");
        } else if (mood == "just okay") {
            console.log("Hello, I am feeling just okay");
        }
    }
};
james.speak("great");
james.speak("just okay");

P.S. I had used a switch statement because I was tired of using if statements. You might call it an artistic choice.


#4

why would use if statements?

you can simply log the string + variable to the console, done?


#5

I tried that (first thing I did actually)... I received a syntax error.
...
...
...
...
Now that's just weird, I just tried it that way again... and it totally worked:

var james = {
    job: "programmer",
    married: false,
    speak: function(mood) {
        console.log("Hello, I am feeling " + mood);
    }
};
james.speak("great");
james.speak("just okay");

#6

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