Introduction to Functions in JS: 11. Functions recap


Continuing the discussion from Lesson 11:Functions Recap....who is Susie?:

Hello, can somebody help me with this? My first thought was to code this in the same format as I see codewhiz71790 mentioned above (at least I hope his post is visible above mine; this is my first time on the forum. If not the link to the whole discussion is at the beginning of my post.)

My code is as follows, and when I click "Save and Submit Code" the output box simply says [Function] but the lesson says "Way to Go! -Start Next Lesson". Shouldn't the output be "Hi, I am posting on this forum."? Is so, where did I go wrong? Thank you for your time!

var nameString = function (name ) {
	return ("Hi, I am" + " " + name);
nameString("posting on this forum.");


You need to call the function inside your log.


Your function is correct and as you call it by nameString("posting on this forum."); the exercise is fine. BUT the value of nameString("posting on this forum."); is never used in the progress so you don't see it (not even as an echo of the last value as it is not the last statement). After this you have this statement console.log(nameString); which prints the variable containing the function so you're told that this is a [Function] which is true but not so interesting. What would make more sense would be to wrap the function call nameString("posting on this forum."); inside the console.log to see the returned result printed on the console.


I replaced lines 5 and 6 with...

console.log(nameString("posting on this forum."));

...and got the output I was expecting. That does make more sense! I had thought either method would produce the same output, but your explanation cleared up my confusion. Thank you & cadecodes very much for your assistance! :smile: Have an awesome day!