Good evening, everyone!
I'm new to this site, I'm learning javaScript and I'm still a noob, I got stuck in this and I can't simply understand what's wrong.
I have the following instructions:
1.Write a function called nameString()
2.It should take name as a parameter.
3.The function returns a string equal to "Hi, I am" + " " + name.
4.Call nameString() by passing it your name, and use console.log to print the output.
I wrote:
var nameString = function (name) {return "Hi, I am" + " " + name;
};
nameString (Myrrh); console.log (name);
But the console says ReferenceError: Myrrh is not defined.
I tried to write then nameString (Myrrh); console.log (nameString); but it didn't work either. If I write nameString (name); console.log (nameString); it no longer throws that error but the console prints out [Function] and not the ''Hi, I am Myrrh'' message I'm supposed to get.
I'm new to functions, and as far as I understood you simply assign a value in parentheses to the parameter when you call the function, meaning, nameString (Myrrh); should be alright because ''Myrrh'' is the value of (name). This has perfectly worked for other exercises but won't work for this one. In addition, calling the function and logging inside the curly braces won't change anything either. And, of course, changing ''name'' inside the curly braces to something else doesn't work, either. I also changed var nameString = function (name) to function nameString (name) since they seem to mean the same or something similar (not sure about the difference) but it still throws the same error.
I'm stuck, no idea how to solve this. I'm probably missing the silliest detail as a beginner but no matter what I change it throws an error.
PS: If it helps anything, it's an exercise from Code Academy.
Thanks in advance for your help!
Aucun commentaire:
Enregistrer un commentaire