函数getSubTotal如何知道有4个项目?我知道isays itemCount * 7.5但是建立itemCount的代码在哪里?
var orderCount = 0;
function takeOrder(topping, crustType) {
console.log('Order: ' + crustType + ' crust topped with ' + topping);
orderCount = orderCount + 1;
}
function getSubTotal(itemCount) {
return itemCount * 7.5;
}
takeOrder('bacon', 'thin');
takeOrder('pepperoni', 'regular');
takeOrder('pesto', 'thin');
takeOrder('pesto','ronii');
console.log(getSubTotal(orderCount));
答案 0 :(得分:0)
orderCount设置为0,并在调用函数takeOrder 4次后增加到4。
然后传递给函数getSubTotal作为输入,所以在这种情况下,itemCount与orderCount相同,即4