How does a function work?please help me


#1

// Write your foodDemand function below.
// Last hint: In your reusable block of code, end each line
// with a semicolon ( ; )
var foodDemand = function {
console.log("I want to eat" + "pizza" +food);
}


#2

You have to add the parameter (food) because it tells the computer what type of variable (data) you are working with
You also have to assign a value to food because otherwise the computer wouldn't know what string food represents

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

As you can see the value "cookies" is assigned on the last line so the computer knows that food represents (or is equivalent to) the string "cookies".
You should now have: I want to eat pizza and cookies


#3

thank you,but it's saying "It looks like you didn't put quotes around the food you gave foodDemand!"...what does that mean?


#4

On the last line you could write
foodDemand("example")
because it specifically tells the computer the value you are assigning to what function.

Also remember that spaces also count as strings:
console.log("Example + " " + "Example)
would print our Example Example, not ExampleExample