Function Recap


#1

My code is this:

var nameString = function (name){
console.log("Hi, I am" + " " + name);

};
nameString( "Garrett" );

nameString( "Joe" );

It prints what it's supposed to, when I try to move on it says "Oops, try again. Hmm, it looks like your nameString() function doesn't return 'Hi, I am Susie' for the name Susie."

It does print "Hi, I am Susie" though


#2

Try to return the string inside the function, not to print it.

And then use it like this:

console.log(nameString("Garrett"));

#3

Hi, So I used this for my code on 11. Functions recap. The code works, but nothing shows up on the screen. What am I doing wrong?

var nameString = function (name ) {
return console.log("Hi, I am" + " " + nameString("Kelsey O'Keefe"));

};


#4

There is nothing on the screen because you are not calling the function. The code is not executed.

But this code doesn't work. If you call the function with some string like this:

var nameString = function (name ) {
    return console.log("Hi, I am" + " " + nameString("Kelsey O'Keefe"));
};
nameString("Kelsey O'Keefe");

you will see the result - infinite recursion.
You are calling the function inside the body of the function (recursion) and there is no condition to stop this.