You probably should be using &&
(which means and), not ||
(which means or).
With your current code, one of the first two options are always going to be run because if the speed is greater than 60 (and thus makes it to the first else if
), then it is always going to be either greater than 60 or less than 72. You want it to be greater than 60 and less than 72.
An updated example:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Penalty</title>
</head>
<body>
<form>
<label>Fine:</label>
<input type="text" id="speed" size="3">
<input type="button" value="Submit" onclick="sSubmit()">
</form>
<p id="answer"></p>
<script type="text/javascript">
function sSubmit () {
var speed = parseInt(document.getElementById("speed").value);
var result;
if (speed <= 60){
result = " No fine" ;
}
else if (speed >= 61 && speed <=71 ) {
result = "Fine is 100€" ;
} else if (speed >= 72 && speed <=75 ) {
result = "Fine is 170€" ;
} else if (speed >= 76 && speed <=80 ) {
result = "Fine is 200€" ;
} else {
result = "Day-fine ";
}
document.getElementById("answer").innerHTML= "<p>" + result + "</p>";
}
</script>
</body>
</html>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…