How does a function work?


This is my code some how it does not work?

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

this is the error

Oops, try again. There was a problem with your syntax.


Hi you should call your function like that

foodDemand("here type your food name")


But wouldn't you be printing it out????!?!?


Consider this line as a single statement:

console.log('I want to eat watermelon');

It can only run once, and cannot be changed. However, if we wrap it in a function wrapper and allow it to accept inputs, we can re-use the core text with variation.

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

To execute the code, we use a call expression,


In the above, 'Watermelon' is called the argument, which in the function is a formal parameter given by the variable, food. Notice that food takes on the value, Watermelon?


Oh ok I get it now thanks for helping me