Default Parameters


#1

I have a question by this Default Parameters exercise . There are three parameters assigned to the function, how can I mange to give input for one of the parameter but keep the other two with the default value?

For example: Item 1 has an input of tea but the item 2 and item 3 should output the default value.
I try to code, but didn’t success.


#2

please show what you tried, so we can see where you go wrong. Thank you

just provide one argument at function call? Then the second and third parameter should get the default value


#3

Hi yunkuo3,

Your function Call should look like:

makeShoppingList(‘tea’);

The output would look like:

Remember to buy tea
Remember to buy bread
Remember to buy eggs

In fact, if you Call:

makeShoppingList(‘tea’,'coffee);

The output would look like:

Remember to buy tea
Remember to buy coffee
Remember to buy eggs

(took me a while to find it but . . .)

if you Call:

makeShoppingList(undefined, ‘tea’,'coffee);

The output would look like:

Remember to buy milk
Remember to buy tea
Remember to buy coffee

Hope this (now) helps :smile: