javascript基础代码练习之超速罚款

<!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>

实验结果截图:

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
THE END
分享
二维码
< <上一篇
下一篇>>