Whats wrong with my code?lesson 11


#1



Replace this line with your code. 

var nameString = function (name) {

return("Hi,I am"+" "+ name);	
};
nameString("Susie");


#2

I mean, are you getting an error message?


#3

it says" it looks like your nameString() function doesn't return 'Hi, I am Susie' for the name Susie."


#4

Hi first you should put

nameString("Susie");

inside a console.log() the the string you should print is

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

instead of

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

no need of () around your string.


#5

nameString("Susie");
var nameString = function (name) {

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

it says error


#6
you should put 

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

look well what I said

and not the string


#7

@jay8978 Since you went through the trouble of writing a function, you should print the output of your function rather than rewriting the sentence (double the work; be lazier! :slight_smile: ). (Also note that the variable name can't be seen outside of the function's brackets, or "scope".)


#8

console.log( nameString("Susie") );
var nameString = function (name) {

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

i tried everything :frowning:


#9

@jay8978 Don't give up now, you are so close! In this case the problem is that the call needs to be below the function (move it to the bottom).

Later you may see ones that look like

function nameString(name) {
    (code)
}

I think these you can call before and after where they are written, but if it looks like var = function... it can only be called after.


#11

One more thing, you want to print the value of your variable, not "name", right? :slight_smile:


#12

omg i got it

var nameString = function (name) {

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


#13

Congrats @jay8978 :slight_smile: I knew you could do it! Keep it up! :raised_hands:


#14

@jay8978 Oop, sorry; maybe I misread the program the first time, because I just realized, does it print? This reminds me of your previous question actually. For future reference, I think the aim of the exercise is to try calling your function and printing it at the same time like this: console.log(functionName(argument));.


#15

yep youre right! heres the right code!!! @msfrisby
var nameString = function (name) {

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


#16

You got it, @jay8978! :clap::clap::clap: Bonus question: do you see any repetition that can be eliminated?


#17

nameString("Susie") right!


#18

Yes! A winner is you! :raised_hands::tada: