0
第一次海報 - 我試圖運行這個函數,它帶有兩個參數,收入和過濾器狀態,並使用一些switch語句將收入調整到稅後值。我明顯在某處犯了一個錯誤,因爲函數始終返回0而不是我的預期結果。Switch語句返回錯誤結果
所有建議表示讚賞!
感謝, 亞當
var afterTaxes = function(income, filer) {
var adjusted = 0;
if (filer === "single") {
switch (income) {
case income < 9325:
adjusted = (1.00 - 0.10) * income;
break;
case income < 37950:
adjusted = (1.00 - 0.15) * income;
break;
case income < 91900:
adjusted = (1.00 - 0.25) * income;
break;
case income < 191650:
adjusted = (1.00 - 0.33) * income;
break;
case income < 416700:
adjusted = (1.00 - 0.35) * income;
break;
case income >= 416700:
adjusted = (1.00 - 0.40) * income;
break;
};
} else if (filer === "married") {
var adjusted = 0;
switch (income) {
case income < 9325:
adjusted = (1.00 - 0.10) * income;
break;
case income < 37950:
adjusted = (1.00 - 0.15) * income;
break;
case income < 91900:
adjusted = (1.00 - 0.25) * income;
break;
case income < 191650:
adjusted = (1.00 - 0.33) * income;
break;
case income < 416700:
adjusted = (1.00 - 0.35) * income;
break;
case income >= 416700:
adjusted = (1.00 - 0.40) * income;
break;
};
};
return adjusted;
};
afterTaxes(150000, "single");
這是什麼編程語言? –