我正在使用税收计算器,但我无法使用它。我得到的唯一结果是 NaN,我找不到我的代码有什么问题。如果用户输入为 450 000 或更多,则输出应该是他们工资的 32%,否则为 28%。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="description" content="Skatt">
<meta name="author" content="Gandalf">
<title>Taxes</title>
</head>
<body>
<input type="text" id="salary" value="0" />
<button id="button">Calculate tax!</button>
<h2 id="salaryOut">Your salary is NOK:</h2>
<h2 id="taxOut">You should pay taxes with the amount of:</h2>
<script>
var button = document.getElementById("button");
button.onclick = function() {
var salary = document.getElementById("salary");
salary.value = 0;
var salaryOut = document.getElementById("salaryOut");
salaryOut.value = salary;
var salaryOut = document.getElementById("taxOut");
taxOut.value = parseFloat(salaryOut.value);
if(salaryOut.value<450000) {
taxOut.value = salaryOut.value * .28;
}
else {
taxOut.value = salaryOut.value * .32;
}
salaryOut.innerHTML = ("Your salary is NOK: " + salary.value + ",-");
skattUt.innerHTML = "You should pay NOK: " + taxOut.value + ",-";
}
</script>
</body>
</html>