我为我的一个类做了这个代码(请记住它的初学者类,我们刚开始学习其他的if)。它应该记下某人的姓名,SSN,工资,时间以及最终的工资与税收。
<!DOCTYPE html>
<html lang="en"
<!-- Author: Sidney Stephens
Assignment ? - Part ?: Title: ?
Date: [[date:%d/%m%Y %H:%M"%S]]
Description: ???
-->
<head>
<meta charset="UTF-8" <!-- Character Setter -->
<title>CMIS102 » Sidney Stephens » Assignment ? Part ? </title>
<script>
document.write("<h1>Payroll Calculator</h1>")
window.alert("This is the Dynasty Casino Payroll Program.");
sName = window.prompt("Who's payroll?","");
document.write("<p>Name: </p>" + sName);
sSSN = window.prompt("What is their SSN?","");
document.write("<p>SSN: </p>" + sSSN);;
sEntry = window.prompt("Hourly Rate?","0");
var fRate = parseFloat(sEntry);
document.write("<p>Rate: </p>" + fRate);
sEntry = window.prompt("How many hours worked?","0");
var fTime = parseFloat(sEntry);
document.write("<p>Time: </p>" + fTime);
if (fTime > 40)
{
var sDiff = fTime - 40;
var fDiff = parseFloat(sDiff);
document.write("<p>Overtime Worked: </p>" + fDiff);
var sRaw = (fRate * 40) + ((fRate * 1.5) * fDiff);
var fRaw = parseFloat(sRaw);
document.write("<p>Pay Without Taxes: </p>" + fRaw);
if (fRaw <= 1000)
{
var sFinal = fRaw * 0.85;
var fFinal = parseFloat(sFinal);
window.alert("You will recieve $" + fFinal);
document.write("<p>Final Pay: </p>" + fFinal);
}
else if (fRaw > 1000)
{
var sExtra = fRaw - 1000;
var fExtra = parseFloat(sExtra);
var sfinal = (fExtra * 0.75) + (1000 * 0.85);
window.alert(sFinal);
var fFinal = parseFloat(sFinal);
window.alert("You will recieve $" + sFinal);
document.write("<p>Final Pay: </p>" + sFinal);
}
}
else if (fTime <= 40)
{
var sRaw = 40 * fRate;
var fRaw = parseFloat(sRaw);
document.write("<p>Pay Without Taxes: </p>" + fRaw);
if (fRaw <= 1000)
{
var sFinal = fRaw * 0.85;
var fFinal = parseFloat(sFinal);
window.alert("You will recieve $" + fFinal);
document.write("<p>Final Pay: </p>" + fFinal);
}
else if (fRaw > 1000)
{
var sExtra = fRaw - 1000;
var fExtra = parseFloat(sExtra);
var sfinal = ((fExtra * 0.75)) + ((1000 * 0.85));
window.alert(sFinal);
var fFinal = parseFloat(sFinal);
window.alert("You will recieve $" + fFinal);
document.write("<p>Final Pay: </p>" + fFinal);
}
}
</script>
</head>
<body style="color: #000000; background-color: #FFFFFF">
<p>This is the template</p>
</body>
除非sRaw超过1000然后由于某种原因它一直说NaN或未定义,否则它对我来说很好。我们并没有真正深入了解它的吸引力。我们几乎得到了算法的工作。提前谢谢。
答案 0 :(得分:0)
您的代码中存在拼写错误
else if (fRaw > 1000)
{
var sExtra = fRaw - 1000;
var fExtra = parseFloat(sExtra);
var sfinal = (fExtra * 0.75) + (1000 * 0.85);//here, change sfinal to sFinal
window.alert(sFinal);
var fFinal = parseFloat(sFinal);
window.alert("You will recieve $" + sFinal);
document.write("<p>Final Pay: </p>" + sFinal);
}
花了很多时间才能找到这个简单的小错字!!道德你应该学习“错字;永远不要让它们发生”