JavaScript, Functions Recap


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-6LzGd/2/3?curriculum_id=506324b3a7dffd00020bf661


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;
	
};


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


#2

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


#3

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.


#4

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


#5

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