3. Literally Speaking - Using an If-Statement?


#1



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


I know, that the best/common way to solve this task ist by using

console.log("Hello! I am feeling " + mood);

At first I wanted to use an If-statement though...

I am guessing that it doesn't work, because I can't really access the parameter of the function inside the function/inside the if-statement...

I hope you guys can understand what I mean by that... Here's my code, please tell me why this doesnt work.


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");


#3

I don't think this code is correct... because the function doesn't take parameters and printing both sentences should have to to with the method being called two times with different parameters.

Also: Please take the time to read my question before you answer.


#5

Still not related to my question :wink:

And by the way: Just because your code is accepted doesn't mean you got the point of the exercise.
I am not here to pass the lessons, but to understand what I am doing.


#7

Ok, if you're missing my point or don't understand my question: Please don't respond anymore, thanks.


#8

Nice job Marie, your error is caused cos of the semicolons in the end of the " if " statement.
var james = {
job: "programmer",
married: false,
speak: function(mood) {
if(mood === "great") {
console.log("Hello, I am feeling great");
}; // here is your error,delete the semicolons
else if(mood === "just okay") {
console.log("Hello, I am feeling just okay");
};
}
};

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


#9

Aha, so my first idea works after all :slight_smile:
Thank you Dragan!


#10

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