获得“确保已定义所有需要的变量。”在此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
};

最佳答案

您需要在if语句上修复语法:

if (hourOfDay > 20 || hourOfDay < 6) {
    costs = costs + nightSurcharge;
}


Javascript使用花括号来标识代码块。

09-16 19:40