Whats Wrong with My Code?


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");



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:


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


Then this happened...

//I programmed

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


//This came out

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


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


you should use the function name to call a function:


not sure how i missed that.


when yo call Function use var not parameter so

name = what you want to eat


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


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

foodDemand =("pizza");


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