I am trying to to follow along with the passengerList array, and I cannot get it to function properly. I have tried to enter in debug logs and such, but I never get a hit for "list[i] == undefined". I am lost on whats wrong, if someone could tell me I would appreciate it!
var passengerList = [];
/* create a function to add passengers. If the list is empty, add the entry, If the list is not empty, add name to first empty space. return list. If end of list is reached, add to end. */
function addPassenger(name, list) {
if(list.length == 0) {
console.log("List is 0 length.");
list.push(name);
} else {
for(var i = 0; i < list.length; i++) {
console.log("I is at : " + i);
if(list[i] == undefined){
console.log("i, " + i + " is undefined!");
list[i] == name;
return list;
} else{
if(i = list.length - 1){
console.log("I is at the end, index : " + i);
list.push(name);
return list;
}
}
}
}
}
moderator: Thanks for trying to format it! You quoted the code instead, which doesn't format it. You need to instead format (i.e., escape) it, which I did here.