Getting an error with 11. It works if I do the code wrong


#1

As I understand it the console.log should be inside the function and it works. But the lesson does not accept until it is outside and then it doesn't work.


#2

Because I am only allowed one picture per post here is the other one.


#3

Well return is the keyword that a) returns a value to the caller and b) returns to the caller (meaning it exits the function). So using anything after return will just be ignored that is why you're first approach fails. The second one is actually correct and calls the function so the test function is fine with it. What somehow is often misunderstood is that calling the function and printing the value is actually one statement:

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

or

var message = nameString("joe");
console.log(message);

But you call the function which returns the value (which is not used anywhere) and then you print the name of the function which tells you the correct but worthless answer that this is a [Function].


#4

Thank you that worked. Can't believe I forgot about it even though it was in the unit before.


#5

The lesson is not so straight forward about this. Thanks for the detailed break down! I was confused and had the exact problem as user gurenmarkv.