4. How does a function work?


#1

this is my code
// Write your foodDemand function below.
// Last hint: In your reusable block of code, end each line
// with a semicolon (:wink:
var foodDemand = function ("Pizza") {
console.log("I want to eat" + " " + food);
};
it also says SyntaxError: Expected identifier


#2

I changed it to
// Write your foodDemand function below.
// Last hint: In your reusable block of code, end each line
// with a semicolon (:wink:
foodDemand = function(food)
{
console.log("I want to eat" + " " + food);
}
and it says Oops, try again. You did not call foodDemand


#3

You need to call foodDemand by adding after you close the repeating code block like;

foodDemand( "x" )

Replace x with whichever food you desire. So, it would look like,

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

#4

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

unexpected string, i don't know whats wrong.


#5
var foodDemand = function("food") {

the parameters is a variable name which gets it's value from here:

foodDemand("steak");

so after function it must be food not "food"


#6

thanks stupid mistake.