0
我一直在編程以下功能並理解了所有內容,直到這一行。不確定組合操作員在功能中執行什麼操作
cost += nightSurcharge;
我用我if
語句條件語句是用來給nightSurcharge添加到晚上8點至早上6點之間的成本。
我需要了解的是+=
是否只是說如果滿足條件就將nightSurcharge添加到成本?
// add a parameter called hourOfDay to the function
var taxiFare = function (milesTraveled, hourOfDay) {
var baseFare = 2.50;
var costPerMile = 2.00;
var nightSurcharge = 0.50; // 8pm to 6am, every night
var cost = baseFare + (costPerMile * milesTraveled);
// add the nightSurcharge to the cost starting at
// 8pm (20) or if it is before 6am (6)
if (hourOfDay >= 20 || hourOfDay < 6) {
cost += nightSurcharge;
}
return cost;
};
'成本+ = nightSurcharge;'等同於'成本=成本+ nightSurcharge;' – j08691 2012-08-14 15:04:57