Help with Functions


#1

People please, what is wrong with my code below:

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

I am learning JS. Today is my fist day of study. Sorry by my "stupid" ask.


#2

Hi @salatiel1987! Umm ok. The way you initalize your function is wrong. This is how you initalize it:

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

See the documentation.

Hope this helped if it didnt please Reply saying so and ill do my best to help! Good Luck!


#3

Not that amanuel is wrong or doing too much, but you can opt out of writing new before function in this example if you would like. Less syntax to worry about I suppose.

And don't worry about asking any dumb questions! There is definitely no such thing when it comes to coding...this is all so complicated and we're all here to help each other


#4

Seems to be ok although it's not common to see this function declaration as it is not covered in the track :smile:
The problem is that you do no call your function, e.g. foodDemand("pizza");.
@bboyjoonie What do you mean with this?

but you can opt out of writing new before function in this example if you would like. Less syntax to worry about I suppose.