3.Litteraly Speaking


#1

My code for some reason doesnt print out the text... it gives me this odd error but lets me pass.. RangeError: Maximum call stack size exceeded
var james = {
job: "programmer",
married: false,
speak: function( ) {
console.log("Hello, I am feeling " + james.speak())
}
};

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

#2

Should your speak function really call your speak function? That's a never-ending loop, and keeping track of all the function calls takes space on the stack


#3

So I should find a way not to use speak function to call my speak function? o.o
Those two bottom rows of code were already there.


#4

That's not what I said.

consider this:

function f() {
    f();
}

#5

no I think you are doing it right, or right-ish. james.speak() is inside but what you are calling is outside. I don't see anything wrong with that... other than its not complete yet. Still trying to figure that part out. We need a for, or something in the function( ) though. hint says to put a parameter like mood in there. Not sure how to bring it full circle though.


#6

sorry for double post but for some reason this:

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

gets me a good job move on, even though it is wrong, and gives me an error. So it must be "close" to the answer.


#7

Ok found the answer. Not sure how this is suppoed to work, but the correct answer is:

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

so the other guy was right, to much recursion..... I don't really get this one at all.


#8

Basically, what is happening is: When the function speak:function(mood) is called the mood part contains what is written in james.speak("this section ");

So if I wrote james.speak("Awesome!") under the function it would do this:
console.log("Hello, I am feeling" + " " + "Awesome!")

I hope this helps you to understand :slightly_smiling:


#9

I didnt figure out that james.speak is a function and("great") is a parameter that we are calling the function with ._. i feel lame


#10

Thx it's good answer for me to understanding:)