Javascript Declaring a function as an argument

Hello everyone,

I’m completely stuck in an exercise and I feel a little stupid because it is apparently easy:

Show me the code!
Let’s declare a function called personalGreeting. This function takes a name as an argument and it should print to the console a personalized greeting. We’re already testing it, all you need to do is declare it.

/

/ declare your function here



personalGreeting('Clarice'); // outputs Good morning, Clarice
personalGreeting('Dave'); // outputs Good morning, Dave
personalGreeting('Vietnam'); // outputs Good morning, Vietnam

This is where I am so far:

var personalGreeting = function (){// declare your function here
console.log('Good morning' + (''));
};

personalGreeting('Clarice'); // outputs Good morning, Clarice
personalGreeting('Dave'); // outputs Good morning, Dave
personalGreeting('Vietnam'); // outputs Good morning, Vietnam

Output

Code is incorrect

Make sure you created the function as instructed

Good morning

Good morning

Good morning

Hello @core9029753909, welcome to the forums! All you need to do is declare a function with an argument, and print that argument to the console (with the greeting).
The syntax for a function declaration:

const someFunction = argument => {
//code
}

Note, in the case of more than one argument (or no arguments), you need to use parentheses:

const someFunction = () =>{
//code
}

Using const is better practise, as it means the function can’t be reassigned. You can still use var and let, though.

2 Likes

Thank you very much for your answer! however, I tried what you’ve said and it still doesn’t work

What did you write? Don’t copy my templates word for word.

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