我在運行此代碼時收到一個NaN
錯誤。我一直在試圖找出爲什麼現在有一段時間,不能爲我的生活。JavaScript NaN錯誤循環
爲了澄清,我試圖接受;
客戶
應付總金額有多少客戶在進入
function Summarise() { ID = prompt("Enter a Customer ID number ", -1) while(ID != -1) { var gasUsed = 0 var total = 0 gasUsed = prompt("Enter amount of gas used ", "0") ///Standard Rate is used to assist in the calculation of customers in excess of 60 Gas Used StandardRate = 60 * 1.75 if(gasUsed <= 60) { total= gasUsed * 2 document.write("Customers ID: " + ID) document.write(" has gas usage of " + gasUsed) document.write(" and owes $" + total) document.write("<br/>") } else { total= (gasUsed - 60) * 1.50 + StandardRate document.write("Customers ID: " + ID) document.write(" has gas usage of " + gasUsed) document.write(" and owes $" + total) document.write("<br/>") } var totalowed = total + totalowed var totalcustomers = ++totalcustomers ID = prompt("Enter a Customer ID number ", -1) } document.write("Total amount owed $" + totalowed) document.write("<br/>") document.write("Total Number of customers:" + totalcustomers) }
這是因爲你使用了一些變量,它是不確定的,並提供明確的值.. – DeDevelopers 2014-09-29 11:50:27
快速提示:分號不(真的)可選。 – 2014-09-29 11:51:59
我還是非常非常新的JavaScript,你能多解釋一下@ DeDevelopers – 2014-09-29 11:57:50