Function Syntax


#1

Hi guys, I kindly need your help to figure out what's wrong with the code here

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

SyntaxError: Unexpected identifier

var sayHello greeting = function (name) {
    console.log("Hey " + "you"); 
};

#2

no spacing in function/variable name allowed. :wink:


#3

Thank you,
so should I do this:
var sayHelloGreeting = function (name) {
console.log("Hey " + "you");
};

?
Then it gives me "Oops, try again. You did not call the greeting function. Pass it a name!" :confused:


#4

Have you called your function sayHelloGreeting somewehere? And have you passed your function sayHelloGreeting a name-argument? also your function doesn't log out the name. Instead it concatenates two strings. Make sure you log out something like this:

console.log("Hey " + name);


#5

Thank you for dealing with my ignorance.

Probably, I'm not the brightest person in a family)

So, I did this:

var sayHello("Erik") = function (Erik); {
console.log("Hey " + Erik);
};

And ofc, got another "there's a problem with your syntax" message.


#6

Try this instead:

var sayHello = function (name) {
    console.log("Hey " + name);
};

sayHello("Erik");

#8

Gosh)
So:

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

// On line 11, call the greeting function!
sayHello("Nika");

Good news - now it runs the code; bad news - "You did not call the greeting function. Pass it a name!"


#9

rename your sayHello function into greeting. Also instead of this:

console.log("Great to see you," + " " + name);

write this:
console.log("Great to see you, " + name);


#10

Thanks a lot, kind person!

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

// On line 11, call the greeting function!
greeting("Nika");

It works! )


#11

You are very welcome. :slight_smile:


#12

so much work for a simple greeting message???

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

// On line 11, call the greeting function!
greeting("daniel")


#13

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.