What did I do wrong?


#1


// 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);
};


#2

Are you on 4.) How does a function work? on 3.) Intro to Functions in JS?


#3

4.) How does a function work?


#4

Ok. So lets look at the instructions for this lesson: 1.) Declare your function and call it foodDemand. 2.) 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. 3.) 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); 4.) Call the function and put in a specific food you want!
1.) Declare your function and call it foodDemand. While you have foodDemand in your code it is not in function form. The basic function form is:

variable functionname equal to function(parameters) {

So let us set it up like that knowing we will have a function with a parameter.

var foodDemand = function(placeholder) {

Var is obviously short for variable and placeholder is just holding a place for our parameter for step 2.

2.) 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. So let us make our food parameter now in our function!

var foodDemand = function(food) {

As one can tell, we replaced placeholder with food because this is where parameters go in a function.
3.) 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); So where does this block of code go? Inside the function! As always when given an exact code, as you have done, copy and paste it directly into your code from the instructions just to avoid any mistakes in grammar or typing. So let us add our reuseable code block:

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

We are almost done! Now to step 4
4.) Call the function and put in a specific food you want!
I used to struggle with function calling and have several forum posts about it. However, honestly, it is quite simple. All calling is, in my less than professional explanation, is the name of the function along with the idem of the parameter in it. So, in this example, all we have to do to call the function is type foodDemand with the parameter. What do we use as our parameter this time? Is it food again? No! You are wanting an actual food in the place of food so that when your sentence is console.log to the screen it shows an actual food. So for example I used Whopper for mine because I love Burger King Whoppers! So my function calling would be like this:

foodDemand("Whopper");

And my output on the screen was this:

I want to eat Whopper

This should be all you need to pass this lesson and I hope your able to understand it all! Also, sorry if this explanation is somewhat basic and "childish" I tend to explain things more casually and more like I would explain something to a child just because I know everyone can understand me that way lol


#5

Wow! Thank you so much! I guess I just needed another perspective to understand.


#6

No problem! And yeah so true! Which is why the forums is so nice because you can get multiple fresh pairs of eyes to look at stuff and help you solve problems when you just get stuck. It is like having a free tutor system xD Anyhow, if you need anymore help just post again :smiley: :thumbsup:


#7

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