Function syntax !please help


#1

My code for this exercise is :

var greeting = function ("Anna");
{
console.log("Great to see you" + Anna);
};
// On line 11, call the greeting function!
greeting("Anna")

Code does not run as syntax is wrong:' unexpected string"

Thank you for your help


#2

This is a bit unclear, let me know if you want me to restructure it

var greeting = function(name) {     no semi-colon before the {


console.log("Great to see you" + " " + name);    as " " makes a space and you want the name function.


greeting("Anna")  all other { } where in the correct places so no need to change them

#3

Hi, I had change it to this....still struggling!!! seems to be easy but I am struggling...:scream:

var greeting = function("Anna")
{
console.log("Great to see you" + " " + Anna);
};
greeting("Anna")


#4

You're putting a string where your parameter in the function should be: function("Anna") is wrong

Also instead of having "Anna" in your console.log: ("Great to see you" + " " + Anna); You need to change it to what you have in your parameter. If you do not understand or cannot figure it out still, let me know. :slightly_smiling:


#5

Thank you for your reply. I think I am going to loose my mind here. :confused:
Now I still "unexpected indentifier?"

var greeting = function (Great to see you) {
console.log("Great to see you," + " " + Anna);
};
greeting("Anna");


#6

GOT IT!!! FINALLY: laughing:

var greeting = function (Anna)
{
console.log("Hi," + " " + Anna);
};

greeting("Anna");

THANKS FOR YOUR HELP!!!


#7

GOT IT!!! FINALLY: laughing:

var greeting = function (Anna)
{
console.log("Hi," + " " + Anna);
};

greeting("Anna");

THANKS FOR YOUR HELP!!!


#8

Yup! You got it! :slightly_smiling: Great job.


#9

YES!!

Finally ! Thanks again! It is logical ! I just did not have that logic! :laughing:

var greeting = function (Anna)
{
console.log("Great to see you," + " " + Anna);
};

greeting("Anna");


#10

Could you explain why there is extra " " between "Hi"+ &+Anna?
Is it always existing?
Thank you for the help in advance.

Ella


#11

It's just to space the words. You could just remove that extra space and do console.log("Hi, " + Anna); which will print "Hi, (name)!". If you did console.log("Hi," + Anna); it would print "Hi,(name)"


#12

Thank u so much.
I could ve erased & tried myself before asking. haha silly me. thanks a lot.
:slightly_smiling:
Ella


#13

Don't be afraid to ask questions :slightly_smiling: Happy coding!


#14

hi both ,

I had also noticed that code works when I do not write the space in " " , what i had done I had used " hi "(Hi and space in the bracket which save a bit of time:) Anyway, that was my new discovery with this bit. Thanks