Tying it All together, Syntax errors


#1

In this section on Javascript Functions, we are supposed to correct the syntax of this poorly written greeting function.
I cant seem to get it correct nor can I write a line of code to pass anything through the function. I will attempt to past my code here and would appreciate any input. Thanks.

var greeting = func (name){
console.log("Hello" + "" +"name");
};


#2

@mccbjnn,

You will have to use the function keyword......


#3

var greeting = function (name){ //func must be writen as -function-
console.log("Hello" + " " + name);
//console.log prints:
//"Hello" - 5 characters
//+ " " - 1 space (takes 1 space as if it is 1 character
//+ name - it doesn't need quote, it's a parameter, try with and without and you'll see the difference
};
greeting("Andrew"); //calling the function, name parameter is Andrew

Hope it helps!


#4

Thanks for the explanation !!!


#5

Hi ikustom,
I did write
var greeting = function (name)
{console.log("Hello" + " " + name);
};
greeting("Jeanne");

But the code bit rendered as Hello name. It didn't pass my name through.What do you think happened?


#6

Yes, difference is in -"name"- and -name- if you look closer