1.In script.js, create a new variable at the top of the file named groceryList and set it to an array of strings,
"Bananas", "Milk", "Eggs", and "Bacon"
2.Create a second variable named message and set its initial value to the String,
"Please pick up the following from the store: "
3.After you've created the two variables, create a loop that will loop through every item in the groceryList array.
4.Inside the loop, use string concatenation to add each item within the grocery list to the end of the message, separated by commas.
5.The final grocery item should not have a comma at the end.
6.You will need to use an if statement to conditionally add the comma after each item.
You should concatenate each grocery item and the comma as two separate steps.
(Hint: You can determine if an individual grocery item is the last item in the array by comparing its index (i) to the length of the array. If the index is equal to the array's length minus one, it is the last item.)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Result: After the loop, log the final message to the browser console. It should read:
"Please pick up the following from the store: Bananas, Milk, Eggs, Bacon"
I'v got to number 4 but have no clue where to go from there???
"Bananas", "Milk", "Eggs", and "Bacon"
2.Create a second variable named message and set its initial value to the String,
"Please pick up the following from the store: "
3.After you've created the two variables, create a loop that will loop through every item in the groceryList array.
4.Inside the loop, use string concatenation to add each item within the grocery list to the end of the message, separated by commas.
5.The final grocery item should not have a comma at the end.
6.You will need to use an if statement to conditionally add the comma after each item.
You should concatenate each grocery item and the comma as two separate steps.
(Hint: You can determine if an individual grocery item is the last item in the array by comparing its index (i) to the length of the array. If the index is equal to the array's length minus one, it is the last item.)
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Result: After the loop, log the final message to the browser console. It should read:
"Please pick up the following from the store: Bananas, Milk, Eggs, Bacon"
I'v got to number 4 but have no clue where to go from there???