JavaScript, Functions Recap


So i'm having trouble figuring out why my code comes out as "Hi, my name is undefined"

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



You didn't give nameString anything to work with in your console statement. In the line above it, you did.


This ought to help, your variable/function nameString is complete. You made a small typo saying ar instead of var. Also, console.log needs a semicolon after it. You can also delete nameString("Megan"); and put you name inside the name string in the console like so, console.log(nameString("Megan"));.

I know that this isn't really related, just a little tip. Instead of writing in your return statement, return "Hi, I am" + " " + name;, write return "Hi, I am " + name;. Notice that I added an extra space at the end of the first string; this has the same result as what you wrote, only it is faster, easier, and more efficient. You should learn about it pretty soon (if you haven't already).

Hope this helped :slight_smile: Have fun programming.


That did it! Thank you so much! I really appreciate the tips!


No problem :slight_smile: I'm always glad to help you or anybody else with anything that you should need help with.