I need help figuring out whats wrong with my code and how to use console.log to print the output


#1

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

this is my code now when i try to see if it works it say that "Paul" is not defined. but when i do this:
var nameString = function(name){
return("Hi, I am" + " " + name);
nameString(Paul)
};
console.log(nameString)

and it prints out: [Function], like that. and i can change what im printing to like "O" or "T" and it still says that it is correct.


#2

Hi,
try this.

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

#3

thanks it worked. i really appreciate the help. i had tried this code already i just had called the nameString function twice lol.


#4

You already got a solution so here the explanation of your errors:

nameString(Paul);

here you get the "Paul is not defined error" because Paul is not wrapped in "" or '' and is therefor confused with a variable name which is obviously not defined anywhere. You don't see the [Function] printed because the error already interrupted the execution of your program.

In the second version you put the function call after return, it is still wrong but as return exits the function this line is never executed. Last but not least the [Function]. This is caused by the fact that you don't call the function but just try to print the function name so it telly you "I am a function" which is as true as it is not helpful :smile:


#5

hey everybody here's my code but it's not working out, I believe it's correct but it give me a typeError saying:
TypeError: console.log is not a function

help me out here guy's please!!

here's my code:
var nameString = function (name) {
return ( "Hi, I am" + " " + name );
};

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


#6

do this console.log(nameString("Kazuto"); )


#7

This often happens when you used console.log = value because this overwrites the console.log function. If it's just that problem refreshing the page should do the job. That resets the javaScript.