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


#1

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


#2

The above is a parameter variable. Remove the quotes.


#3

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


#4

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


#5

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


#6

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


#7

You forgot about = before function keyword.


#8

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


#9

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.


#10

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


#11

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