Chapter 11, Functions Recap


#1


I have spent 20 minutes making minute changes to my code though through the hints and previous forum posts to my best analysis this code is correct. any input as to why it states it is incorrect would be appreciated. Thank you.


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


#2

What error are you getting? Syntax or a codecademy error? I don't see any problems with syntax, but I may be missing something. You can also combine your strings by using the space at the end of "Hi, I am"

return "Hi, I am " + name;

#3

I'm getting an error in this exercise, too.

My console is printing exactly what it should. But, I'm getting a crap error saying "oops, try again. It looks like you didn't print anything to the console! Did you remember to console.log() the results of passing your name to the nameString() function?

Which is funny because the console log says:

"Hi, I am batman"

With the following code:
var nameString = function (name) {
return "Hi, I am" + " " + name;
console.log(nameString);
};
nameString("batman");

Also tekkie1618 is telling you specifically to not follow line 3 of the instructions.
The function returns a string equal to "Hi, I am" + " " + name.
Yeah, you can include the space in another portion of the line instead of as it's own section. Not expressly following the instructions does run the risk of failing the exercise though.


#4

I got it to work with this:

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


#5

I saw someone else use this format which seems very clean. Nope, I didn't think of it myself, and I don't know if I've learned anything from it.

Not too happy with the teaching from code academy. I sure am grateful for the forum community!

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


#6

You're trying to print the function itself in your console.log(). The parameter that you set for your function is name so use console.log(name)


#7

In your function, nothing after your return line will execute. It basically ignores your console.log. You should experiment with your function and add multiple return lines with different strings to execute. See what happens.


#8

Thanks! That tells me a lot.

I wasn't expecting to include:
console.log(nameString);

And have something appear in my console that sure does look like what I told it to say and have the issue be that no console.log was performed.

I'm hip deep in the rock/paper/scissors thing right now. Will try to come back to exploring return functionality!


#9

Oh yeah, derp, didn't catch that. Return is the end of the function.


#10

I solved this... for whatever reason my code was this.
var nameString = function (name) {
return "Hi, I am" + " " + name

};
console.log(nameString(name));


#11

hey after a few tweaks i finally made it prit my name
and here is how i did it but it also prints [ Function: nameString]
the instructions are confusing reversed in line 4

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

};
console.log(nameString);
nameString("george")


#12

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