11. function recap


#1

Can you tell me what the problem is here?

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

Referenceerror is: Khadz is not defined.


Code is correct output is displayed twice and an error also shown
#2

Khadiz is a name, so it should be a string


#3

Just put quotes around Khadz.

BEFORE: console.log(nameString(Khadz));

TO: console.log(nameString("Khadz"));

Without the quotes, the system will think that Khadz is a variable --> REFERENCE ERROR: Khadz is not defined

Hopes this helps


#4

having this problem too. can someone help?


#5

please make a new topic, this will give you a template which asks for all the details needed to help. We are not magicians, we can't fix: i have the same problem.


#6

Can someone elaborate on the purpose of adding console.log() again? (What function does it play and why is it needed, aside from the instructions asking for it). Because you can just call nameString() and get the same answer. Thanks!!


#7

console.log() will log something to the console, its also console behavior to log the last value, so now because its the last thing happening, its displayed, but what if you had more code? You needed console.log, otherwise, nothing would log


#8

Ahh I see. Thank you!


#9

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