Function syntax


#1

Please, Help me. I'm stuck here.

// Below is the greeting function!
// See line 7
// We can join strings together using the plus sign (+)
// See the hint for more details about how this works.

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

// On line 11, call the greeting function!
var sayHello = function ("samjhana") {
console.log("Hey," + " " + "samjhana");
};

What's the mistake?


#2

// On line 11, call the greeting function!
var sayHello = function ("samjhana") {
console.log("Hey," + " " + "samjhana");
};

You didnt call the function greeting.

Calling means

greeting("MyName");

#3

Thank you codmakr but it doesn't work.
It says there was a problem in your syntax.


#4

Please show me your new code


#5

You used the wrong parameter in the function declaration;

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

should be

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

then to call it, you do it like this;

sayHello("Samjhana");

Do you understand?


#6

Thank you jibblyj.
It really works.


#7

you could just said : greeting("your name")
and it will run just fine .


#8

Correct.

// Below is the greeting function!
// See line 7
// We can join strings together using the plus sign (+)
// See the hint for more details about how this works.

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

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

#9

This wouldn't affect how your code runs, but you don't need to separate spaces from text. You could just write

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

It's a bit less work. :slight_smile:


#10

Thanks all of you!!!


#11

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