我對javascript有太多的麻煩。我應該使用函數來製作一個簡單的薪水檢查程序。我不知道我在做什麼錯。我也必須將payrate
和taxrate
更改爲十進制格式。你如何把它放在代碼中?這是我的代碼的樣子。Javascript函數問題
<html>
<body bgcolor="#81DAF5">
<head>
<title>Chapter 4 Assignment 1</title>
</head>
<body>
<script type="text/javascript">
var hoursworked = window.prompt("How many hours worked?", "");
var payrate = window.prompt("What is the pay rate?", "");
var taxrate = window.prompt("What is the tax rate?", "");
var netpay
parseFloat(payrate).toFixed(2);
parseFloat(taxrate).toFixed(2);
function calculatepay()
{
var grosspay= hoursworked * payrate;
var taxamount= (grosspay * taxrate)/100;
var netpay= grosspay - taxamount;
return netpay;
}
document.write("<h1><b>Hours Worked: " +hoursworked+ "<br></h1></b>");
document.write("<h1><b>Hourly payrate: " +payrate+ "<br></h1></b>");
document.write("<h1><b>Tax rate applied: " +taxrate+ "<br></h1></b>");
document.write("<h1><b>Net Pay = " +calculatepay+ "<br></h1></b>");
</script>
</body>
</html>
'hoursworked','payrate'和'taxrate'在哪裏定義?你在做什麼回報價值? –
你有什麼問題? – SLaks
該程序開始向用戶詢問提示。說「工作了多少小時,你的工資率是多少,稅率是多少?」 – jaramore