I need help on introductions to functions in JS Lesson 4


#1

I can not get my code with a function to work and I do not know what is wrong somebody please tell me what is wrong here are the directions and my code:
Directions:
Let's break down exactly how a computer thinks when it sees the code for a function.

var functionName = function( ) {
// code code code
// code code code
// (more lines of code)
};

The var keyword declares a variable named functionName.
The keyword function tells the computer that functionName is a function and not something else.
Parameters go in the parentheses. The computer will look out for it in the code block.
The code block is the reusable code that is between the curly brackets { }. Each line of code inside { } must end with a semi-colon.
The entire function ends with a semi-colon.
To use the function, we call the function by just typing the function's name, and putting a parameter value inside parentheses after it. The computer will run the reusable code with the specific parameter value substituted into the code.

Instructions
Let's make a function that tells the world what you want to eat.

Declare your function and call it foodDemand.
You can call the parameter anything you like. But we'll call it food because that is the thing that is going to change each time we call the function.
Your reusable block of code follow this. Surround it with the right brackets. The code you want to repeat is: console.log("I want to eat" + " " + food);
Call the function and put in a specific food you want!

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

Please help me and thank you!!!!!!!!


#2

You have to call your function. So it should look like this.

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

You want to put down your function name (in this case foodDemand) and follow it with what you want (Pizza)
and you get this bit of code: foodDemand("pizza");
I hope I helped!


#3

THANK YOU THANK YOU THANK YOU!!!!!!!!!!!!!!!
I would have never gotten that I was on the totally wrong track.

if (Var myQuestion = "Answered" {
console.log("THANK YOU THANK YOU THANK YOU once AGAIN!!!!!!!!!!!!!!!")
}


#4

Lesson #4
I am having a challenge with the syntax. Could someone straighten me out?

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


#5

First of all you're lacking a ) to close the console.log function. And the second thing is that calling a function inside itself is pretty dangerous, as the function won't run at all and if you make it run, it will create some sort of infinite loop as every function spawns another function. So move the foodDemand("Brussel sprouts"); outside of the function.