Javascript Function recap


#1

I am at the javascript function and it tells me that I am not passing my name to the function i created - this is my code ...var nameString = function(name) {
return "Hi, I am" + " " + name;
console.log(nameString);
};
nameString("Alberto")

can you please help ?


Replace this line with your code.


#2

What is the error message? Please post a link to the exercise. Thanks.

var nameString = function(name) {
    return "Hi, I am" + " " + name;
    console.log(nameString);        // line does not belong
};
nameString("Alberto")

#3

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

the error message reads

Oops, try again. It looks like you didn't print anything to the console! Did you remember to console.log() the result of passing your name to the nameString() function? thank you


#4

Try this,

console.log(nameString("Albert"));

#5

it says there is a problem with the syntax either if I put your line in the function or outside the function


#6

and if I delete the console.log line and leave the code as it is it prints both my name and another line with a different name


#7

Please re-post your code. Thanks.


#8

var nameString = function(name) {
return "Hi, I am" + " " + name;
};
console.log(nameString("Alberto"));
nameString("Alberto")


#9

The above line may be removed. Just call the function the one time.


#10

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

this one is the code .. now when I save it it says you did not console.log but the function print in the console where should i put the console.log(nameString) or do I need to set a var for "Hi I am .... " and then return it ?


#11

This is the line you were to remove. Use the other line I gave you to try.

console.log(nameString("Alberto"));

Sorry, there was a typo in my example. Fixed now.


#12

it tells me that there is a syntax error . unexpected string literal


#13

See above. I fixed the typo.


#14

i corrected your typo myself no worries but still same error message


#15


#16

Hey albert, this is what you are suppoused to write..

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

};

nameString("Albert")
console.log(nameString)


#17

That will output [Function]


#18

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

console.log(nameString("Alberto"));

#19

thank you for your help .. it worked


#20

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