这是一个基本的 JavaScript 代码,用于计算给定值的“提示”。我在这里做错什么了吗?它给了我null数组或NaN代替我的数组内容。
var john = {
fullName: 'john smith',
bills: [124, 48, 32, 268, 180, 42],
calcTips: function () {
this.tips = [0];
this.finalvalue = [0];
for (var i = 0; i < this.bills.length; i += 1) {
var percentage;
if (this.bills[i] < 50) {
percentage: .2;
}
else if (this.bills[i] >= 50 && this.bills[i] < 200) {
percentage: .15;
}
else {
percentage: .1;
}
this.tips[i] = this.bills[i] * percentage;
this.finalvalue[i] = this.bills[i] + this.bills[i] * percentage;
}
}
}