4. How does a function work?


#1

Don't know what to do...

var functionName = function (Pizza) {
console.log("I want to eat" + " " + "food");
functionName(foodDemand);
};


#2

A JavaScript function is a block of code designed to perform a particular task.

A JavaScript function is executed when "something" invokes it (calls it).


#3

The instructions ask us to create a function with the name, foodDemand. Substitute this everywhere you have written, functionName.

Where you have Pizza in the parameter, the instructions ask us to write, food, a locally declared variable which will receive the argument we pass to the function when we invoke it.

Where you have written, "food" there should be no quotes. Remember, it is a variable and variables do not have quotes.

Where you have written foodDemand in the argument, it should be a string value, such as "pizza".

Finallly, move the closing curly brace up one line so that it is above the function call expression.


#4

var foodDemand = function (food) {
console.log("I want to eat" + " " + food;
foodDemand(Pizza); }

Like this?


#5

Almost. Two things...

Because the curly brace is after the function call expression, it never takes place. Second, the argument needs to be a quoted string.

};

foodDemand("Pizza");

#8