3. bug in codecademy?


#1


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

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


this is what my code look like and it returns,
"Oops, try again. It looks like your speak method doesn't properly take in a single argument and output the correct string."

but if i change it to


#2

HI this line

console.log("Hello, i am feeling great");

shoudl be something llike that

console.log("Hello, i am feeling " + text);

the same for this one

console.log("Hello, i am feeling just okay");

#3

speak is method (a function inside a object) which has a parameter (text in this case), which holds the value you pass when you call the method:

james.speak("great");

so now text holds the word great, you can use the method paramter to print the desired result. Remember you can join strings and variables with a plus sign:

test = "hello";
console.log(test + " world");

you can do the same with your function parameter text

the advantage of this method, is that you don't need an if/else. It doesn't limit james his speech to two sentences.


#4

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