1. How do functions work? HELP, PLEASE!


#1



//HOW DO I DO IT


Replace this line with your code.


#2

Help us out, please. What lesson is it that you are having trouble with? Please post a link and any attempts you have made, thus far. Thank you.


#3

ok, I will get that in there in a second


#4

var foodDemand = food() {what do I put after this?

Here are the instructions
1. Declare your function and call it foodDemand.
2. You can call the parameter anything you like. But we'll call it food because that is the thing that is going to change each time we call the function.Your reusable block of code follow this. 3. Surround it with the right brackets. The code you want to repeat is: console.log("I want to eat" + " " + food);
4. Call the function and put in a specific food you want!


#5

To declare (define) a function, we write,

var foodDemand = function () {

};

This defines the body of the function as being everything written inside the braces, { // code }.

A parameter is a locally defined variable we write to be a holder of the value we pass in to the function.

var foodDemand = function (food) {

};

The food variable is arbitrarily named, as mentioned above. It helps if we use a name that describes the meaning or purpose of the variable. Here, the author chose food for this reason.

Next we will write the code that goes in the function body; that is, the code snippet that we wish to be able to re-use at any time (the goal of a function is to be re-usable).

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

Note that above the output contains some fixed text (a string literal that does not change) concatenated to our variable (the text that changes with each call to the function).

Finally we call the function with some text to represent the food:

foodDemand("fried chicken");

The output to the display will read,

I want to eat fried chicken


#6

Thank You. I understand it now.