11. Function Recap


#1

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

};
console.log(nameString("Sophian"));

Is there anything wrong with this?


#3

This should work
var nameString = function ( ) {

nameString(James);
};
"Hi, I am" + " " + name;


#4

Sry but no this should not work. the function call is inside of the fucntion and it is not returning anything. You're kind of cheating by using value at that should be returned on the last line of your code but that is not how this exercise was intended. Take @viperkatz's code as an example how it should look like. Or @viperkatz is there anything wrong with it? Do you get an error? Because from what I can see it should be ok.


#5

@viperkatz, and @haxor789. This lesson requires a specific return from the function (E.G No spelling, grammatical, or otherwise incorrect punctuation or spacing errors.) In this case there's a missing space between the " , " comma, and the " I " in your return string. While it's not entirely necessary to add an ending semi-colon to the end of your return statement, I would suggest it to keep errors from forming in the future as it's good practice.

The only thing needed to be fixed is the following:

return "Hi, I am"+" "+name
           ^
//Insert space there

#6

I am having the same trouble as the 1st usere here is my codes

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

with this one i get an error saying "john is not defined"

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

and with this one i get an error saying "missing ) after argument list"
Could you please help me?
Thanks in advance


#7

You need to pass "John" to the function not John. "John" would be a string value, that by the use of onsole.log(nameString("John")), is assigned to name which leads to the output "Hi, I am John. Whereas John would be confused with the name of a variable and as this variable is neither declared nor defined you get the "john is not defined" error. Also never use a semicolon inside of a console.log after it would be ok but never inside. Also what is the difference between your two versions?


#9

semi colon in the return .


#10

Oh i see Excuse me i posted the same code twice due to a copy paste mistake.Thank you good sir ,now i know what to to .


#11

SO WHAT'S WRONG WTH THIS


#12

this should work


#13

Yes it was about the missing space between am and Rufus. Also please rather post code and error messages instead of screenshots as they might get auto flagged as spam if you use too many of them (multiple maybe commercial filehoster links ... :frowning: ). Also one can run the code then and for example spaces are harder to see in screenshots than in copyable text.


#15

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

};
nameString("Maria")
console.log(name);


#16

Name does not exist outside of the function so this probably throws an error. Rather print console.log(namestring("Maria")); and just delete the last line.


#17

http://prntscr.com/916b39
I dont know what is happening here...


#18

try this

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

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

hope it will help you


#19

You are missing semicolon after return


#20

@arcsolver25702 Actually, you don't need semi colons after the return statement.

@boardslayer45069 Your real problem is that you're missing a space between "Hi" and "I". Remember, Codecademy is really picky with following directions.