4.how does a function works?


i made this
var fooodDemand = function(food) {
console.log("I want to eat" + " " + food);
foodDemand ("pizza")
but it says "foodDemand is not definned"
please help!:frowning:


Let's consider a piece of a raw code that executes immediately, but never again (since scripts are linear, top to bottom and stop at the end).

console.log("I want to eat pizza.");

We can never run this code again. It outputs and ends. We can make it print a value we set previous, as in,

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

Again, it will only run once, and end.

Now suppose we would like to make this code re-usable, meaning we can refer to it again and again, each time with a different variable value? That is where a function comes in. It is a re-usable block of code that we can call over and over, without having to write it more than once.

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

Note the spelling. Your function has an extra o.


thanks for the help :smile: i now im in build "rock,paper and scissors"


If you run into trouble with the RPS project, set it aside and continue in the track. Some practice with the concepts before embarking on the project may prove to be invaluable, especially to a beginning coder. .