Introduction to objects II: literally speaking 3/30: Too much recursion?


#1



I've passed the task but it is not printing to the console. The error message says "too much recursion". Any ideas what I'm doing wrong?


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

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


#2

here:

james.speak(mood)

you call the method inside the method, which causes a sort of infinity loop. just log the string + mood to the console


#3

Ok,I tried that, here's my code:

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

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

this time I get an error message saying: Oops, try again. It looks like your speak method doesn't properly take in a single argument and output the correct string.


#4

why are you logging it twice to the console? methods are just function inside a class, so you can call the function with different arguments, to log different moods to the console


#5

Fair enough. I amended it and I'm only logging it once now. Here's the code:

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

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

I'm still getting the error message: Oops, try again. It looks like your speak method doesn't properly take in a single argument and output the correct string


#6

Nevermind, I just found that I didn't have a comma after the Hello in the string. It's working now


#7