How does a function work? 4/13


#1


https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/0/4?curriculum_id=506324b3a7dffd00020bf661#


SyntaxError: Unexpected token cannot find substring u didnt put in a food demand function


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


#2

It would look like you need your foodDemand outside of your function since you are calling your function.

Also this semicolon will cause you problems as well. Get rid of it!


#3

so like put the function on the outside of the
foodDemand ("Noodles") (so here)
i got rid of the semicolon


#4

Did you get another error or did that solve it for you?


#5

another error u didnt print anything


#6

Post your code again for me please and I will paste it into my lesson to look at it. I got that error when I was removing stuff in my code to see where the error was coming from so I am not surprised that error showed up.


#7

ok its right here

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


#8

Ok I am sorry. Apparently I was not clear enough when I said move your calling outside of the function. You don't have to create another foodDemand. Your foodDemand("Noodles") is the correct function call. However, when calling a function, it has to be outside the actual function. The function is between the { } . Therefore, you need to move foodDemand("Noodles"); outside of the } and get rid of the foodDemand you just added. Here is the basic format of how your code should look with the correct calling place:

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

Mine is a little bit more spaced out than yours but that shouldn't matter here.


#9

thx i will try that since im in this kinda class have a wonderful day


#10

You too! I hope it goes well for you in the class! :thumbsup:


#11

it worked
thx for the help


#12

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.