Functions Recap 11 (JS) codes do not work


#1

var nameString = function (name) {

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

};
nameString("SUSIE");

hi guys, can anyone pls help me find out what's wrong with my code? it does not work well,
here is the instruction:

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.


#2

Instead of just calling the function like this

nameString("SUSIE");

try

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

#3

I have the same proble, but it did not work for me. :frowning:

Here is my code:

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

};

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


#4

Can you please help me too? I am facing the same problem And it gives me the error.
Here is my code.

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

};

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


#5

I have figured it out. here is the correct code. All I did is removed " " around name in return function:

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

};

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


#6

Yes that is probably it, as you want to use ur parameter and not just print "Hi, I am name".


#7

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

Try these,


#8

I tried this exact code

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

};

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

and it still says its wrong. Any ides?


#9

No seems to be ok what is the error message?


#10

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

"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?"


#11

Well this console.log message or at least the function call should be outside of the function.


#12

How should it be printed out?


#13

Well first of all anything after a return statement will be ignored as return means... well return. So in order to start the function youll need to call nameString ("Theodoreich") which then will have a value of "Hi, I am Theodoreich". And to show this value you use console.log. So in the end it leads to moving the console.log line outside of the function :smile:

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

#15

remember that when you are writing
return "Hi, I am" + " " + name;
there needs to be a space between the two quotation marks, if not it doesn't read the space, that's what happened to me


#16

I don't know what's going on, but I tried a fair few 'correct' codes and they did not work. I had to reload the exercise before it finally worked.

So, try that.