I get to pass the exercise but I am not sure if its the right answer


Hello, I have a question about calling a function by passing it your parameter, and use console.log to print the output.
My code is as below:

var nameString = function (name) {
	return "Hi, I am" + " "+name;
nameString(console.log("Phoebe"));  // My answer

The output is as below:

"Hi, I am undefined"

Somehow I get to pass this exercise and move on to next but I think the output is wrong.
Can anyone tell me if this is the right answer?


it should be the other way around, you want call nameString("Phoebe") which you want to log to the console


Thank you! I have changed the code and its fine now.
But I have another question, since we can just call the function and it gives us the answer as well, why do we need to use 'console.log' ?


well, in a way it doesn't. Run this code:

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

see how it only outputs the final function call? This is known as console behavior. The chrome console for example has the same behavior, it logs the last value by default.

to log both, we need console.log()

Having a problem with creating a new object

I see! Thank you very much =)


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