В функции createDrinkOrder есть ссылка на passengers.name.
Почему выводит undefined?
var passengers = [{
name: "Jane",
paid: true,
ticket: "coach"
},
{
name: "Evil",
paid: true,
ticket: "firstclass"
},
{
name: "Sue",
paid: false,
ticket: "firstclass"
}
];
function processPassengers(passengers, testFunction) {
for (var i = 0; i < passengers.length; i++) {
testFunction(passengers[i]);
}
}
function createDrinkOrder(passenger) {
if (passenger.ticket === "firstclass") {
alert(passengers.name + "Would you like a cocktail or wine?");
} else {
alert(passengers.name + "Your choice is cola or water");
}
}
processPassengers(passengers, createDrinkOrder);