我需要在家庭作业中做这个,我需要在函数中打印出带参数的else语句。这就是我已经拥有但它没有打印出任何东西。
function getSalaris(x, y) {
var salaris;
//If else
if (x == 'MBO' && y < 1) {
salaris = '1800'
document.getElementById('resultaat').innerHTML = 'Het salaris van de opleiding en ervaring is: €' + salaris;
}
else if (x == 'MBO' && y <= 3) {
salaris = '2000'
document.getElementById('resultaat').innerHTML = 'Het salaris van de opleiding en ervaring is: €' + salaris;
}
else if (x == 'MBO' && y > 3) {
salaris = '2200'
document.getElementById('resultaat').innerHTML = 'Het salaris van de opleiding en ervaring is: €' + salaris;
}
else if (x == 'HBO' && y < 1) {
salaris = '2000'
document.getElementById('resultaat').innerHTML = 'Het salaris van de opleiding en ervaring is: €' + salaris;
}
else if (x == 'HBO' && y <= 3) {
salaris = '2250'
document.getElementById('resultaat').innerHTML = 'Het salaris van de opleiding en ervaring is: €' + salaris;
}
else if (x == 'HBO' && y > 3) {
salaris = '2400'
document.getElementById('resultaat').innerHTML = 'Het salaris van de opleiding en ervaring is: €' + salaris;
}
}
getSalaris('MBO', 2);
这是HTML代码,我真的找不到它的错误。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<!--Link naar js-->
<script src="Script.js" type="text/javascript"></script>
</head>
<body>
<p id="resultaat"></p>
</form>
</body>
</html>
答案 0 :(得分:4)
在加载脚本时,没有id为“resultaat”的元素。在关闭正文标记之前加载脚本。