There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
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});
}
Output:Remember to buy milk
Remember to buy bread
Remember to buy eggs
Remember to buy bread
Remember to buy bread
Remember to buy eggs
Remember to buy eggs
Remember to buy bread
Remember to buy eggs
Is there a reason why a template literal was used in the example? I copied the code from the example and got rid of the template literal and ended up with the same result.
This is what I typed:
function greeting (name = ‘Stranger’) {
console.log("Hello " + name + “!”);
}
I have a question about default parameters. In the example code within the lesson it state’s that.
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});
}
If I’m happy with the first two default values, but I want to change the third one, how do I go about doing this.
I’ve tried the following…
makeShoppingList(,‘Tuna); //Which results in an Unexpected Token error
makeShoppingList( , ,‘Tuna’); //Which results in an Unexpected Token error
makeShoppingList(’ ‘,’ ',‘Tuna’) //Which results in two black items and Tuna
makeShoppingList(‘Tuna’); //Which replaces the first item
makeShoppingList(false,false,‘Tuna’) //Which prints false, false, Tuna.
I’m really confused how you would do this, hope my question makes sense
I have 3 parameters for function with default parameters
calling bio function without “name” parameter,
function bio (name = "hidden", age=21, gender = "male"){
console.log(`Your name is ${name}, your age is ${age}, and you are ${gender} `);
}
bio("",33, "male");
expected output: Your name is hidden, your age is 33, and you are male;
instead I’m getting errors
I have 3 version, how to call it, and none is working