Syntax Error? 4/13 foodDemand


#1

Pls tell me what's wrong with this code:
var foodDemand = function("food") {
console.log("I want to eat" + " " + food);
}
food("eggs")


#2

@chibimaltese2003,

the FUNCTION talk

var myFunc = function( param1, param2) {
       //Begin of  anonymous FUNCTION-BODY
       //VARIABLE -myFunc- has an -anonymous function- assigned
       //this -anonymous function- has 2 PARAMETERS param1 and param2
       //param1 and param2 PARAMETERS are used 
       //as -local- VARIABLES throughout the FUNCTION-BODY

      console.log( param1 + " and " + param2 ) ;

      //End of anonymous FUNCTION-BODY
};

If you want to call/execute the anonymous function
you will have to add a pair of parentheses to the variable myFunc
like
myFunc();
As the anonymous function was defined
as having 2 parameters
you have to provide 2 arguments
in our case 2 string VALUES "Alena" and "Lauren"
like
myFunc("Alena","Lauren");

some quotes from the outer-world:

**argument is the value/variable/reference being passed in,
parameter is the receiving variable used within the function/block**

OR

**"parameters" are called "formal parameters",
while "arguments" are called "actual parameters".**


#3

The foodDemand function should take 1 parameter food.
( and NOT as you do placing a =string= "food" )

Now if you call the foodDemand function
and the foodDemand function was defined as having 1 parameter
you will have to provide 1 argument
in our case a string Value "eggs"
foodDemand("eggs");


#4

Thank you! :smile: :smiley: