Im在javaScript中使用多個複雜語句掙扎着,想知道是否有人可以指引我朝着正確的方向。Javascript - 多個複雜if語句
function findFlights()
{
var yourDestination = readTheDestination();
var yourAirline = readTheAirline();
var yourFare = readTheFare();
if (yourDestination == 'Choose your destination')
{
displayMessage('<B>Please choose a destination city from the Destination menu and then click Find flights again.</B>');
}
else
{
var destinationTime, destinationOperator, destinationFare;
var message = '<B>You asked about flights to ' + yourDestination + '</B><BR>' + "";
for (var i=0; i < flightTimes.length; i++) //flight destinations
{
if // statement // IF flight:
((flightDestinations[i] == yourDestination && // destination = selected destination &
yourAirline == 'Any airline' && // airline = any airline &
yourFare == 'Any price')) // fare <= chosen fare
|| // OR
(flightDestinations[i] == yourDestination && // destination = selected destination &
yourAirline == flightOperators[i] && // airline = chosen airline &
yourFare <= flightFares[i])) // fare <= chosen fare
{
destinationTime = flightTimes[i];
destinationOperator = flightOperators[i];
destinationFare = flightFares[i];
message += destinationTime + ' ' + destinationOperator + '. £' + destinationFare + '<BR>';
displayMessage(message);
}
}
else if (flightDestinations[i] == yourDestination &&
flightOperators[i] != yourAirline &&
flightFares[i] != yourFare)
{
displayMessage('There are no flights to ' + yourDestination + ' with ' + yourAirline + '. Please select Any Airline and try again.');
}
}
這是我到目前爲止,它使我灰色。
呃...有一個問題在這裏? – helloandre 2010-09-13 16:57:29
你應該描述它應該做什麼。 – Pointy 2010-09-13 16:57:37
問題'if'陳述數量?或者是否有更好的方法來完成您向我們展示的任務? – Jakub 2010-09-13 17:01:47