Default Parameters question

https://www.codecademy.com/courses/introduction-to-javascript/lessons/functions/exercises/default-parameters?action=resume_content_item

Hello,
I have a question that how to put a value to a single argument.
Please see below.

function makeShoppingList(item1 = 'milk', item2 = 'bread', item3 = 'eggs'){
  console.log(`Remember to buy ${item1}`);
  console.log(`Remember to buy ${item2}`);
  console.log(`Remember to buy ${item3}`);
}

makeShoppingList('candy');

OUTPUT:
Remember to buy candy
Remember to buy bread
Remember to buy eggs

QUESTION:
How can I change the second item (bread) to ‘candy’ without changing other items?

Thanks for your help.

1 Like

use undefined, since it is undefined it is like you didn’t set it.
In this case:

makeShoppingList(undefined, 'candy');

Hope this helps :grinning:

1 Like

Awesome! Thank you so much! :slight_smile:

1 Like