JS Codecademy返回II - 返回问题

时间:2017-08-10 15:31:09

标签: javascript function

我遇到以下代码问题。当它运行时,它记录我的三个订单,但我得到一个小数为0.它应该将orderCount 3乘以7.5,因为我调用了函数takeOrder三次。我错过了什么吗?

var orderCount = 0;

function takeOrder(topping, crustType){
    orderCount + 1;
    console.log("Order: " + crustType + " pizza topped with " + topping + ".");
}

function getSubTotal(itemCount) {
    return itemCount * 7.5;
}

takeOrder("mushroom", "stuff crust");

takeOrder("pepperoni", "thin crust");

takeOrder("sausage", "sicilian crust");

console.log(getSubTotal(orderCount));

3 个答案:

答案 0 :(得分:1)

您需要增加orderCount

orderCount += 1;

答案 1 :(得分:1)

orderCount + 1;

不会增加orderCount的值。

使用

orderCount++;

相反,这是

的缩写
orderCount += 1;

的缩写
orderCount = orderCount + 1;

答案 2 :(得分:1)

var orderCount = 0;

function takeOrder(topping, crustType){
    orderCount ++;
    console.log("Order: " + crustType + " pizza topped with " + topping + ".");
}

function getSubTotal(itemCount) {
    return itemCount * 7.5;
}

takeOrder("mushroom", "stuff crust");

takeOrder("pepperoni", "thin crust");

takeOrder("sausage", "sicilian crust");

console.log(getSubTotal(orderCount));
  

更改orderCount + 1; to orderCount ++;