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>

实验结果截图:

相关推荐
喵星人工作室11 小时前
C++火影忍者1.1.2
开发语言·c++
basketball61611 小时前
C++ 中的 ptrdiff_t 详解
开发语言·c++
anOnion11 小时前
构建无障碍组件之Slider Pattern
前端·html·交互设计
云水一下11 小时前
JavaScript 从零基础到精通系列:前世今生与编程启蒙
前端·javascript
月亮邮递员61611 小时前
Markdown语法总结
开发语言·前端·javascript
printfLILEI11 小时前
php中的类与对象以及反序列化
linux·开发语言·php
曹牧11 小时前
C#:主线程能够捕获到子线程中的异常
开发语言·数据库·c#
代码中介商11 小时前
深入解析STL中的stack、queue与priority_queue
开发语言·c++
彦为君11 小时前
JavaSE-07-异常机制
java·开发语言·后端·python·spring
Kurisu57512 小时前
雾锁王国修改器下载2026最新
前端·修改器代码