How does a function work ? What is wrong ? Help


Replace this line with your code. 

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


To call a function, you're not setting it to equal anything. You call a function by naming it with the parameters like so:


If your function had multiple parameters, you would say:

testFunction("param1", "param2", 3, 4)


But is this wrong : foodDemand ("apple"); ?
Can I write it like this or not ?


I don't think that it will throw an error, but it's best practice to not have a space.


yes it doesn't work like this, but in the previous example I wrote almost the same example and there was a space and it worked. lIike this : var greeting = function (name)
{console.log ("Great to see you"+" "+name);};
greeting ("emina") ;
What is different here i don't understand


It's the = in your third line that caused the error


When you declare or initialize your function there is some leniance with spacing, as long as your order is there. Spacing between these characters is loose. When you call your function, thats another story. You do need to follow your identifier closely with its parenthesis. Your identifier is a function and so its parenthesis must be conjoined to it.


Yes, that's it, now it works. Thank you for helping


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