得到“确保你已经定义了所有需要的变量。” 在这个 Code Academy Javascript 脚本中。
// 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 costs = baseFare + (costPerMile * milesTraveled);
if (hourOfDay > 20 || hourOfDay < 6)
costs = costs + nightSurcharge
end
return costs
};