How does a function work ? What is wrong ? Help


#1


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


Replace this line with your code. 

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


#2

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

foodDemand("apple");

If your function had multiple parameters, you would say:

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

#3

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


#4

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


#5

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


#6

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


#7

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.


#8

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


#9

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