2
<!DOCTYPE html>
<html lang="en">
<body>
<script Language="JavaScript">
window.alert("Bennet's Used Auto Sales: 2010 Sales"); //window to display the text
var Aqs = prompt("Enter 1st Quarter Sales for 2010 :", ""); // prompts to have user input data
var Bqs = prompt("Enter 2nd Quarter Sales for 2010 :", ""); // prompts to have user input data
var Cqs = prompt("Enter 3rd Quarter Sales for 2010 :", ""); // prompts to have user input data
var Dqs = prompt("Enter 4th Quarter Sales for 2010 :", ""); // prompts to have user input data
window.alert("The Sales Figure for Quarter One is :" + Aqs); //prompts that repeat the inputted number
window.alert("The Sales Figure for Quarter two is :" + Bqs);
window.alert("The Sales Figure for Quarter three is :" + Cqs);
window.alert("The Sales Figure for Quarter four is :" + Dqs);
var totSales = (Aqs+Bqs+Cqs+Dqs); //adds together all inputted data
var avgQSales = (totSales/4); //averages all inputted data
window.alert("The total sales for the year of 2010 for Bennet's Used Auto Sales are :" + totSales); // window to show the variable from above
window.alert("The average Quarterly Sales of 2010 for Bennet's Used Autp Sales are :" + avgQSales);
</script>
</body>
</html>
新的代碼是在上面,窗口顯示正常,但算術的結果是不正確的,我不知道爲什麼。我的目標是讓用戶輸入4個數字並將這些數字相加,然後取平均值,然後我需要顯示它。Javascript Google Chrome,代碼不起作用?
檢查您的開發人員工具控制檯的錯誤 - 'document.write'是如此老派的JavaScript,應該避免 –
我的老師讓我們使用2011年的教科書,並在整個互聯網上有1/5的評論。 。 謝謝您的幫助! –
'document.write()'自2011年以前被認爲是不好的做法。但是如果這是你的老師期望的,那麼我想你在某些情況下必須使用它。請注意,它不應該用於在頁面加載後對頁面進行更改,因此請勿在事件處理程序中使用它。 – nnnnnn