11. Can't see it!? "Oops, try again. Hmm, it looks like your nameString() function doesn't return 'Hi, I am Susie' for the name Susie."


#1



Lesson 11. Function recap


Getting this error, but it does print, Hi, i am **** , also see upload. What am i supposed to do? I am clueless atm. Thanks.

Oops, try again. Hmm, it looks like your nameString() function doesn't return 'Hi, I am Susie' for the name Susie.


var nameString = function (name) {
	return "hi,i am" + " " + name;
};

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


#2

Hi the string should be...

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

instead of

"hi,i am" + " " + name;

#3

Hey, I tried your code and made a little modification and it worked.
Check it out. Try this.


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

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


#4

Same error, how ever Cynthiarose's solution worked. It looks like i just should have copied from the instructions. Thanks you both.


#5

You are welcome. Glad my code worked.


#6

Thank you, other contributors. My problem was similar, but not exactly the same. The code wouldn't pass the test until it had BOTH a console.log() output and a return() output.

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

#7

At any rate, it should be checking JS not spelling and grammar.


#8

I did copy from instructions and it didn't work. Console log has to be outside of the function for it to work, which isn't real error but there.


#9

HI if you need help you should post your code..


#10

I just did, in separate thread. It lets me pass the lesson, but it's clearly not working...


#11

Thanks for your code, but I've got a question.
Why does A work instead of B? Thanks!
A. console.log(nameString("Al."));
B. console.log{nameString("Al.")};


#12

Sorry, I'm not much of an expert in JavaScript and I don't really know why B doesn't work and A does.:frowning: But I think it's because we use {} mostly for code blocks and functions, right??


#13

because in (nameString("Al.")); you have two closings one is for (nameString) which has a opening and closing and the other set is for ("Al.") if you do (NameString("al.")} you will be leaving nameString open as you are closing only the ("Al.") and not adding the ) that closes nameString so you would have nameString open and close the function when nameString needs to be closed also.


#14

i just don't know how did you do?i likes the same form,what the diffierent between
them?when i copy it ,it works!


#15

I wrote it wrong by mistake and it passed anyway Lol

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

}

nameString(console.log("Daniel."))

It returns this:
Daniel.
"Hi, I am undefined"

I did it by mistake but It passed anyway, maybe the lesson needs to give an error in case that happens.
I fixed it to

console.log(nameString("Daniel."))

But the lesson passed Ok with the error.
:stuck_out_tongue:


#16

@1233210000abc The curly brackets are for the JavaScript code and the parenthesis are for the name of the functions and parameters (If I understand correctly).

You will see the that what's between curly brackets is the JavaScript code that runs when the function is called.

At least that's what I am understanding at this moment.
Hope it helps

:slight_smile:


#17

I think the check is only looking for a specific way to write the function and not accounting for other solutions.
Believe the “return” in the instructions is how you are supposed to identify it. See below

var nameString = function (name) {
	
// 	console.log('Hi, I am' + ' ' + name); Works but doesn't count in this setting
    return "Hi, I am" + " " + name;
};
console.log(nameString('Susie'));

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.