Intro to functions in JS, lesson 4. Whats wrong?


So I've tried pretty much everything, and it keeps saying, "You did not declare foodDemand" when I clearly have. I'm not sure if it's a bug or just me. please help. Here's my code:

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

foodDemand = ("Burger");


The above is a parameter variable. Remove the quotes.


do you need the = after foodDemand when you call your function?


No. @evildrak, remove = after function name. You call function by foodDemand("Burger");


Thanks. That was really obvious. I appreciate the help. :smile:


Hi there! Here's what I'm doing:
var foodDemand function(food) {
console.log("I want to eat"+" "+food);
And here's what it says:
SyntaxError: Unexpected token function
Anyone know what's the trouble? Thanks!


You forgot about = before function keyword.


Are the spaces between the plus signs and the parenthesis within the console.log necessary or preferable?


Not necessary, but preferable. The style guides generally tend to recommend white space around operators. It helps readability. While JavaScript doesn't require white space in many cases, style guides suggest we be generous with white space and define our nesting with indentation, closing curly braces on own line, and so on. Space is free.


A post was split to a new topic: Am i missing something here?


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