更新: 我可以看到兩個投票來解決問題,因爲不清楚我需要什麼。這裏是我需要的:我需要一次超過1,100,000的價格來計算相應的價格,例如,在1,100,001和1,200,000之間的價格將是220美元,對於1,200,001到1,300,000之間的點將是240美元等,沒有限制,所以例如4,500,001和4,600,000的價格將爲720美元。javascript數學計算案例
我需要做一個javascript caluclation它是這樣的:
1-500,000點$ 30/100,000點
500,001-999,999點$ 25/100,000點
1,000,000點$ 20/100,000點
我有案件開關,將檢查值,然後得到正確的總和,但我想知道我可以做,例如,如果用戶輸入4,500,000點或一些超過1,100,000的隨機值。 這是我目前:
if (Number(amountOfPoints) > Number(0)) {
switch (true) {
case (amountOfPoints > 0 && amountOfPoints <= 100000):
{
price = 30;
break;
}
case (amountOfPoints > 100000 && amountOfPoints <= 200000):
{
price = 60;
break;
}
case (amountOfPoints > 200000 && amountOfPoints <= 300000):
{
price = 90;
break;
}
case (amountOfPoints > 300000 && amountOfPoints <= 400000):
{
price = 120;
break;
}
case (amountOfPoints > 400000 && amountOfPoints < 500000):
{
price = 150;
break;
}
case (amountOfPoints > 500000 && amountOfPoints < 600000):
{
price = 150;
break;
}
case (amountOfPoints > 600000 && amountOfPoints < 700000):
{
price = 160;
break;
}
case (amountOfPoints > 700000 && amountOfPoints < 800000):
{
price = 185;
break;
}
case (amountOfPoints > 800000 && amountOfPoints < 900000):
{
price = 210;
break;
}
case (amountOfPoints > 900000 && amountOfPoints < 1000000):
{
price = 235;
break;
}
case (amountOfPoints <= 1000000):
{
tweetsPrice = 200;
break;
}
default:
price = 0;
break;
}
}
任何幫助,我怎麼能計算,如果點是> 1,100,000?它應該每100,000增加20美元。
爲什麼jQuery的標籤?我看不到。 – j08691
@ j08691它的精神在於 – DiegoSalazar
似乎if語句是按順序排列的,而且您不需要同時執行比較的兩個「邊」。 –