因此,工作的一些代碼,我沒有發現問題與我的循環中的第二個函數它不斷返回40,我認爲循環寫入正確。我猜它是在if和else條件下傳遞的值?如果(par_hour < 40),它來自parseFloatJavaScript的麻煩parseFloat和if/else循環
function addEmployee()
{
var employees = new Array();
employees[0] = window.prompt("Enter employee name","Bob");
var hours = new Array();
hours[0] = window.prompt("Enter How many hours you have slaved away! ","4.5");
var wages = new Array();
wages[0] = window.prompt("Enter your hourly wages.","10.00");
alert("test");
calculateSalary(hours,wages);
alert("How about now");
document.write(regHours);
}
function calculateSalary(hours,wages)
{
par_hour = parseFloat(hours[0]);
par_wage = parseFloat(wages[0]);
if (par_hour < 40)
{
regHours = par_hour;
}
else (par_hour >= 40)
{
regHours = 40;
}
alert("why wont you work");
}
<html>
<head>
<title>Matt Beckley Week 2 Assignment</title>
<script type ="text/javascript" src="script1.js">
</script>
</head>
<body>
<h1>Weekly Gross Salary</h1>
<table border="1">
<tr>
<th>Employees</th>
<th>Total Hours</th>
<th>Reg Hours</th>
<th>Reg Pay</th>
<th>OT Hours</th>
<th>OT Pay</th>
<th>Weekly Salary</th>
</tr>
</table>
<a href="salary.html" id="reload" onclick="addEmployee();">Add Employees</a>
</body>
</html>
您可以使用'alert()'或'console.log()'來輸出par_hour和par_wage嗎? – 2010-01-25 09:56:56
你應該給你的員工加班費:-) – YOU 2010-01-25 09:57:57