Need help fixing function


#1


Hello,
I am trying to figure out what I did wrong with the function below. The error message is:

Oops, try again. Hmm, it looks like your nameString() function doesn't return 'Hi, I am Susie' for the name Susie.


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


#2

there is a crucial word in this sentence: return, to return something, use the return keywrod


#3

Thank you for the quick reply!


#4

so what do they want you to return then? i can get the console to say the correct sentence only with the return its not working anymore. can you show me the correct script?


#5

this:

console.log("Hi, I am" + " " + name);

should be returned, but is currently logged to the console instead.

return literally means the function is handing you something back, this doesn't have to get logged to the console. we can store the returned result:

example = function(){
   return "hello world"
} 
x = example()

and then log the stored result to the console:

console.log(x)

or if you don't want to store the returned result, you can call console.log directly on the function call


#6

I have looked at this for help and am still confused. My code is:

var nameString = function (name) {
return("Hi, I am" + " " + name);

};
nameString(Fraser);

Where am I going wrong?


#7

Fraser should be a string. Names are often represented as strings.


#8

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