4. How does a function work?


#1


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


When I call the function and include the parameter "Mexican," the called function does not include the parameter. It merely reads, "I want to eat food"

What am I doing wrong?


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


#2

Hello @jrc571,

For string concatenation to work, you must put the name of the variable without quotes. Otherwise, it will register it as a string...


#3

You also forgot a semi colon on line 5.


#4

Thank you @bartholomewallen!

This problem arises when I put the parameter Mexican in parentheses without quotes:

(at bottom) Oops, try again. It looks like you didn't put quotes around the food you gave foodDemand!

(in console) ReferenceError: Can't find variable: Mexican


#5

Thank you for the reminder, @arccoder39324.

Is this how it should look?

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


#6

please remove the quotes


#7

Thank you, @puristaja! That did the trick.


#8

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