Functions Recap #11


#1



I cannot get away from the syntax error.

Identifier expected

Replace this line with your code. 
var nameString = function (name) {
	
return "Hi,I am"+" "name;

console.log ("Shannon");
};


#2

@wndrwn,
If you use the so-called concatenation
you do that by using the plus-sign-+
thus

return "Hi,I am"+" "+name;

where you should use the EXACT string output as is asked for in the Instructions !!!!


#3

Hi @wndrwn,

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

I've added some space to your code. Can you see where the problem is now? Hint: what are you returning?

Some other notes:

  • Once you return the program escapes the function, i.e. the lines below return will not be executed.
  • You need to call the function for it to run.

Hopefully these pointers help you, but please let me know if you have further questions.

frisby


#4

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

console.log (nameString);

};
nameString ("Shannon");

This prints fine now but it says I didn't print anything to the console


#5

@wndrwn

Please refer to my first bullet point: the lines below return [in the function] will not be executed.
Does that give you an idea? If you still need help can you please share a link to the exercise?

frisby

PS: You can also write your string as: "Hi, I am " + name if you like.


#6

Thanks! I got it!!! Sometimes I can't see the forest for the trees


#7

Glad to hear it! No worries, happens to me too :slight_smile:


#8

its not working please can you write the answare


#9

@datarunner71858 Hi Raslan,

If you can't figure it out I suggest you post a new topic with your code and what you are having trouble with. CodeCademy has a really easy template for new posts you can follow! :nerd:


#10

Mine worked but it kept printing "[Function]" before "Hi, I am..."
How do I get rid of "[Function]"?


#11

@mikaelamula Depends on what your code looks like... (*coughs*)


#12

#13

If you have an error create a +New Topic with code, lesson and error :slight_smile: