Lesson Instructions Not Clear Enough - Lesson 4 Introduction to Functions in JS


Lesson 4. How does a function work? - https://www.codecademy.com/courses/javascript-beginner-en-6LzGd/0/4?curriculum_id=506324b3a7dffd00020bf661

The instructions did not tell me how to properly operate a function. Please help, I have been stuck on this lesson for a very long time.

"Oops, try again. You did not call foodDemand!"

Here is my code:

// Write your foodDemand function below.
// Last hint: In your reusable block of code, end each line
// with a semicolon (;)
function foodDemand() {
    console.log("I want to eat" + " " + food);


First you need to name your function by using the variable command. Then name your parameter (everything inside the curly brackets) and include your code, yours of which seems to be fine. Then lastly you need to call the function using its var name. By the end of it yours should look like this:

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

//Hope this helps.


To call a function, put it's name followed by ();. For example, if I have a function called foo, I'd cal it like this: foo();


The code shows an argument, food but there is no parameter to support it.

function foodDemand(food) {

To call the function, simply use its name with (), and insert the argument in the parenthesis: