How does a function work output


I think the output to the code is wrong. I expect the output to be I want to eat fried food but all I get is I want to eat fried

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




There's no string in your code with the letters f-o-o-d so it seems unlikely that it would print that sequence of characters.


Huh, what do you mean? - the word/string food is in the parenthesis of the console.log - I thought the console.log would add the word food to the end of the output.

The codecademy system says it's correct anyway still but I'm not entirely sure it is.


Your code contains some data that represent characters.
You have three of them. They are called strings. They are:
" ", "I want to eat", "fried"
Nowhere in your code is there data that represents the text f-o-o-d.
If you don't have such data, then you should not expect it to appear in the output. Pehaps you mean for that data to be in the code, but then you would have to add it.

If there's a part in the code that you believe currently contains that data, then you will need to reconsider what that something is.

Note that none of these are getting printed, despite being in your code:

var foodDemand = function (food)
console.log (""+""+food);



That is because none of that is data representing text. They are all instructions to be carried out, not data.


can I ask why the below is in the console.log parenthesis when it's not being used in anyway?


from here...

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

Why is it even there? - what purpose does it serve? lol


If it's not used in any way, then removing it would have no effect. Is that the case?

(Also, see updated previous response, I have a bad habit of making edits a few minutes after posting)


removing the word food changed it to just I want to eat, but adding the word food made it I want to eat Burrito which is strange


ah I think I've got it now, the word food in the console.log string is the placeholder of the function and the function is called foodDemand so when I call it my foodDemand value is it outputs just Burrito...

var foodDemand = function (food)
console.log (" "+" "+food);




If I have a function called add, and I use it like so:

add(2, 3)

Then what do you expect the result of that to be?
Would it be strange that changing the 3 to a 4 would cause the result to be 1 greater?

If the function went something like this:

function add(a, b) {
    return a + b;

Then what are a and b in that function? How do they relate to how I invoked the function?


They would be added together I think when called


it seems to be its just like one big loop


By the way, thanks for the help ionatan :wink:


var foodDemand = function (a){
console.log("i want to eat "+""+"banana"+" "+"mango") ;
console.log(foodDemand("banana")) ;


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