11. Functions recap


#1

The console.log reads [Function], how is that?
It supposed to be correct because I can proceed, but ofcourse it's not.


#2

here:

nameString("Arjan");

you call the function, to log what the function returns you should use console.log here

this code:

console.log (nameString);

is another function call, but because its without parentheses, JavaScript tells you its a function


#3

So console.log is printing "function" because it's telling you what nameString is. Place your name inside what you're looking to print out with console.log. Hope this helps.

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

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

#4

But if he has already passed the function his name, why does he need to print it out again in order for it to work? Feels weird and clunky to me.


#5

My Code is:-
var nameString = function (name ) {
return ("Hi, I am" + " "+ name);
};
nameString("SONU");
console.log (nameString);

Output is:-
[Function: nameString]
My question is that - Why I can't see the output "Hi, I am SONU". Explain!


#6

here you call the function:

nameString("SONU");

to log to the console what the function returns, you should pass this as argument to console.log:

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

the line below you call the function without parentheses, then JS tells you this is a function


#7

THANKS,
I am getting you now what u want to say:wink:


#8

Why would it be this way? console.log(nameString("Andrew"));

So far in the course we have always first called the function independently. For example, in Lesson 4 we print the result as part of the function and define food outside of the function.
For example:
var foodDemand = function(food) {
console.log("I want to eat" + " " + food);
}
foodDemand("Chicken")

How are new coders expected to know how to define a function and print it in the same line? Introducing a new concept like this near the end of a unit seems antithetical to quality instruction.


#9

to log what the function returns.