Whats Wrong with My Code?


#1


Introduction to Functions in JS 4. How does a function work?


SyntaxError: Unexpected string


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

food=("pizza");


#2

this line:

var foodDemand = function ("food")

food shouldn't have quotation marks ("), it is a variable which will hold the value when calling the function. so inside the function:

console.log("I want to eat" + " " + "food");

food again shouldn't have quotation marks.

and when you call a function, don't use a equal sign:

food("pizza");

equal sign means assign value, that is not the same as calling the function


#3

Then this happened...

//I programmed

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

food("pizza");

//This came out

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


#4

oops, i missed something important, sorry. Your function call:

food("pizza");

you should use the function name to call a function:

foodDemand("pizza");

not sure how i missed that.


#5

when yo call Function use var not parameter so
foodDemand("name");

name = what you want to eat


#6

i perfectly know how to call a function? I don't see the mistake you are mentioning anywhere?


#7

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

foodDemand =("pizza");


#8

This topic is already solved? And that is still a bad suggestions, now you assign a value to foodDemand instead of calling the function.


#9