I am struggling to get my for loop to print out every item in the array, instead of just the last item. Can't seem to figure out where I'm going wrong:
var patients = ["Julia", "Kelly", "Thomas", "Clare"];
function lineOfPatients(line) {
if (!line.length) {
return "Empty"
}
var list = "";
for(var i = 0; i < line.length; i++) {
list += `${i + 1}. ${line[i]}, `
}
return `The line is currently: ${list}`
}
lineOfPatients(patients)
This code snippet returns "The line is currently: 4. Clare,"
My desired output should be "The line is currently: 1. Julia, 2. Kelly, 3. Thomas, 4. Clare"