Struggling with grasping the concept of for loops in arrays. I'm attempting to develop a Thank You card generator and here are the steps I am endeavoring to execute:
- Initialize a new empty array to store the messages
- Loop through the input array, construct the 'thank you' message for each name within the loop using string interpolation, and then append that message to the newly created array
- Once the loop is completed and all messages have been added to the new array, return the updated array.
const names = []
function writeCards(names, event) {
for (let i = 0; i < names.length; i++) {
console.log(`Thank you, ${names[i]} for the wonderful ${event} gift!`);
return names;
}
Uncertain if I'm on the correct path. Appreciate your assistance!