我在使用 javascript 时遇到了很多麻烦。我应该使用函数制作一个简单的薪水程序。我不知道我做错了什么。我还必须将payrate
and更改taxrate
为十进制格式。你怎么把它放在代码中?这是我的代码的样子。
<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>