3literally i don't know what's wrong


#1

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

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

//output
Hello, I am feeling great
Hello, I am feeling just okay
Hello, I am feeling great
Hello, I am feeling just okay

why the result log twice


#2

if(mood="great") { ... }
if(mood="just okay") { ... }

You used assign operator = but need comparsion ===.


#3

awkward,it works,In the morning,i had tried this,it didn't work.some bug?


#4

Please, post your updated code.


#5

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

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

//It works now.Thank you so much.


#6

I am Chinese,It's 17:26 in our country...... not morning


#7

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