html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Nauji</title>
</head>
<body>
<script>
function punish(speed) {
const limit = 120;
if (speed <= limit) {
return '未超速';
} else if (speed <= limit + 20) {
return '超速警告';
} else if (speed <= limit + 24) {
return '罚款100元';
} else if (speed <= limit + 60) {
return '罚款500元';
} else if (speed <= limit + 120) {
return '罚款1000元';
} else {
return '罚款2000元';
}
}
// 测试
console.log(punish(100)); // 未超速
console.log(punish(120)); // 未超速
console.log(punish(130)); // 罚款200元
console.log(punish(150)); // 罚款500元,
console.log(punish(180)); // 罚款1000元
console.log(punish(220)); // 罚款2000元
</script>
</body>
</html>
实验结果截图: