How do I modify console with a parameter in place?


#1

I am having trouble editing. Please look at changing-string-with-parameter

const takeOrder = (topping) => {
  console.log('Order: pizza topping mushrooms ');
};

takeOrder();

Hopefully this helps the community. too.


#2

here:

const takeOrder = (topping) => {

you have a parameter (topping) at your function declaration, but then when you call the function:

takeOrder(/* missing argument */);

you have no argument at function call? If you have a parameter at function declaration, you need an argument at function call, for example mushroom:

takeOrder("mushrooms");

now the argument ("mushrooms") gets passed along to the function parameter, so the value of topping will be mushroom

however, if you have two customers:

takeOrder("mushrooms"); // customer 1
takeOrder("salami"); // customer 2

they both get mushroom, given nothing is done with the function parameter in the function body, see this bit of the instructions:
Modify the console.log to interpolate the topping parameter to print a string like this


#3

Can I use single tickbacks instead? Or does that not work…

For example:
’’‘takeOrder(‘mushrooms’);’’’


#4

of course you can, but that was totally not the point i was making


#5

I added the argument:

const takeOrder = (topping) => {
  console.log('Order:pizza topping mushrooms ');
};

takeOrder('mushrooms');

It is still not working. I think there is a syntax error but do not know what it is.


#6

did you read this:

lets make the example even more obvious:

const takeOrder = (topping) => {
  console.log('Order:pizza topping mushrooms ');
};

takeOrder("mushrooms"); // customer 1
takeOrder("salami"); // customer 2

oh oh, the second customer ordered a pizza with salami, he got a pizza with mushrooms. Customer2 is not happy.

also ensure the string printed is an exact match, after order: you miss a space


#7
  console.log('Order:pizza topping mushrooms ');
};

takeOrder('mushrooms');```

Above is what I put. It keeps saying "expected [function.....
However, I am placing the function. I checked the syntax. Do you see anything else that I'm doing wrong? I had to run a quick chore....

#8

please post your code with format:

so it shows properly, currently you added incorrect symbols trying to make code show

i got no error running your code, can you include a screenshot of the lesson (instructions, code and output)?


#9


#10

I put a space after mushroom and still no result


#11

from the instructions:

Modify the console.log to interpolate the topping parameter to print a string like this:

Order: pizza topped with mushrooms

didn’t interpolate the topping parameter into the string!

run this code:

const takeOrder = (topping) => {
  console.log('Order:pizza topping mushrooms ');
};

takeOrder("mushrooms"); // customer 1
takeOrder("salami"); // customer 2

see how for both customers, we get a pizza topped with mushrooms, while customer 2 wants salami

You included a parameter in your function deceleration, but don’t use this parameter in the function body, even though the exercise asks this of you!

I don’t know how to make it any more obvious


#12

To understand the concept, if I did not include mushrooms and instead put this:

console.log('Order: pizza topped with  ' + topping);
takeOrder('mushrooms');

Would that not accomplish the same thing?

Then I could put pineapple as the takeOrder parameter and it would calculate for pineapple.

I do not know why the editor keeps putting all of my text as code… :-/


#13

no, because now topping is an undefined variable

this is good:

console.log('Order: pizza topped with  ' + topping);

but you need the function declaration:

const takeOrder = (topping) => {
    // console.log here
}

// function call here

given the function parameter (topping) is what defines the variable


#14

but if you already have the function declaration and then you do as I stated…


#15

then you get this:

const takeOrder = (topping) => {
  console.log('Order: pizza topped with ' + topping);
};

takeOrder("mushroom");

which is the correct code


#16

to confirm, the above form follows the instruction:

"Now, let’s include the topping parameter in the body of the takeOrder function.

Modify the console.log to interpolate the topping parameter to print a string like this:" from that exercise?


#17

no, its the correct code but it doesn’t follow the instructions (sarcasm)

Of course if the code is correct, it follow the instructions, how else can it be correct?


#18

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