I got the "food function" right, but I don't understand how it works


#1

Why do I get the same result when I change the parameter value when calling the function?

So I got it right and everything, but if I call the function but change the parameter value to "Pizza", it still comes out as "I want to eat food". I don't understand what the parameters actually do and what changes when I change them?

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

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

#2

when calling the function:

foodDemand("Pizza");

you pass an argument, which is then stored in the function parameter:

var foodDemand = function(Pizza)

so then Pizza is your function parameter, which will hold the argument passes, so if you want to display the argument, use the function parameter:

console.log("I want to eat "+ Pizza);

you can see the parameter as a variable, so you don't have to use " around the function parameter.


#3

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