Help with function


I don't get the following:
Write a function called nameString()
It should take name as a parameter.
The function returns a string equal to "Hi, I am" + " " + name.
Call nameString() by passing it your name, and use console.log to print the output.

var nameString = function (name) {

return nameString "Hi, I am" + " " + name;
console.log (nameString);

The error I get:
Your code doesn't look quite right. Click "Stuck? Get a hint!" if you need help!


what is the name of the function you're calling? name or nameString? are you using console.log to print the function to the console?


The function has to be called nameString, with name as the parameter.
So I wrote:
var nameString = function (name) {

I wrote for the second part in the exercise:
return nameString "Hi, I am" + " " + name; from the hint.

And then I got stuck with the last step.
I wrote:
name("Gabriel"), so that it print outs my name.
But I'm uncertain about how to write the console.log in this case, and what I'm doing wrong.


here, you are writing name to print out your name but your function is called... ?


Instead of calling the function perimeter replace it with the function name that is



And the second thing is : Why you are using console.log? they said to return it. Use



var nameString = function(name) {
return "Hi, I am" + " " + name;


The interpreter says you should check the hint. I think you should.

However, it says to this:

var greeting = function (name) {
    console.log("Hi, I am" + " " + name);

greeting("Gabriel!"); //this is where you call your name on the greeting function that was created.


The hint only says":
The code block in the function should look like:

return "Hi, I am" + " " + name;

Just a reminder: we need to add " " to the string so we have a space between the word 'am' and the word 'name.
So I didn't really help me at all.

Why: return "Hi, I am" + " " + name;
And not: return nameString "Hi, I am" + " " + name;


In case you missed it (it was on a lower-level reply, not a parent comment), you need to add console.log on the line where you call the function:

console.log (nameString("Gabriel"))

because it says to use console.log to print the output of calling nameString with your name


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