我是一個新手,所以對於一個可能的新手問題提前抱歉。Var hundred = parseInt(num_images/100)
有人可以讓我知道這個特定的JavaScript代碼做什麼?程序員讓我高興而且乾燥,我必須今天自己解決這個問題!
Var hundreds = parseInt(num_images/100)
更新:這裏是完整的代碼 - 試圖單個圖像的價格更改爲15 $,而不是$ 10(這是它以前是)我認爲這個問題是在我質疑線。請讓我知道我可以如何改變這一點。真的很感謝所有的幫助!
var totalcost = 0;
var cdcost = 0;
var cdtext = "";
var merchandisecost = 0;
var makecd = false;
function GetCDCost(num_images) {
var hundreds = parseInt(num_images/100);
var remainder = num_images % 100;
if (remainder < 4) {
return (135 * hundreds) + (15 * remainder);
}
else if (remainder <= 15) {
return (135 * hundreds) + 65;
}
else if (remainder <= 25) {
return (135 * hundreds) + 85;
}
else if (remainder <= 50) {
return (135 * hundreds) + 105;
}
else if (remainder <= 100) {
return (135 * hundreds) + 135;
}
}
function UpdateCheckoutCost() {
var html_string = "";
var poster_flag = false; // Is there a poster(s) in this order?
var no_shipping = true; // Shipping flag;
cdcost = GetCDCost(favorites.length);
if (favorites.length < 4) {
cdtext = "CD - " + favorites.length + " pictures @ $15/each";
}
else if (favorites.length <= 15) {
cdtext = "CD - 15 Images";
}
else if (favorites.length <= 25) {
cdtext = "CD - 25 Images";
}
else if (favorites.length <= 50) {
cdtext = "CD - 50 Images";
}
else if (favorites.length <= 100) {
cdtext = "CD - 100 Images";
}
else if (favorites.length > 100) {
cdtext = "CD - " + favorites.length + " Images";
}
'Var'中的'v'應該很小。請參見['parseInt()'](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/parseInt) – Tushar
在parseInt函數中始終使用基數參數。 –
parseInt用於將字符串轉換爲整數,但在此我假設num_images是一個整數,因爲我們正在對其執行數學運算。我不認爲我們需要parseInt – user3509208