11. function recap


#1

i also get an error msg although i put function name with " "
i dont understand what is wrong with my code...

Even when i try it in this way :

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

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

  • which gives the right output i still get an error

11. Functions Recap - Error?
11. Functions Recap - Error?
#3

nameString() function returns string variable. So you need to put returned value to some variable and only after that you can log it:

var result = nameString("susie");
console.log(result);

But you can to call the function inside console.log:

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

In your case you returned string value but not printed it and made mistake when you called the function inside the console.log because you didn't put any arguments there.

Also, here:

var nameString=function(name){
   return "Hi, i am " + name; // forgot ;
};

#4

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