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

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>

实验结果截图:

相关推荐
灵感__idea2 小时前
Hello 算法:贪心的世界
前端·javascript·算法
小成202303202653 小时前
Linux高级02
linux·开发语言
知行合一。。。3 小时前
Python--04--数据容器(总结)
开发语言·python
咸鱼2.03 小时前
【java入门到放弃】需要背诵
java·开发语言
ZK_H3 小时前
嵌入式c语言——关键字其6
c语言·开发语言·计算机网络·面试·职场和发展
A.A呐3 小时前
【C++第二十九章】IO流
开发语言·c++
椰猫子3 小时前
Java:异常(exception)
java·开发语言
lifewange3 小时前
pytest-类中测试方法、多文件批量执行
开发语言·python·pytest
GreenTea4 小时前
一文搞懂Harness Engineering与Meta-Harness
前端·人工智能·后端
cmpxr_4 小时前
【C】原码和补码以及环形坐标取模算法
c语言·开发语言·算法