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>

实验结果截图:

相关推荐
2401_873204655 分钟前
C++中的策略模式进阶
开发语言·c++·算法
xushichao198910 分钟前
C++中的职责链模式实战
开发语言·c++·算法
清风徐来QCQ17 分钟前
js中的模板字符串
开发语言·前端·javascript
成都渲染101云渲染666622 分钟前
Houdini+Blender高效渲染方案(高配算力+全渲染器兼容)
前端·系统架构
2301_8184190123 分钟前
C++中的协程编程
开发语言·c++·算法
add45a25 分钟前
C++中的工厂方法模式
开发语言·c++·算法
java1234_小锋26 分钟前
Java高频面试题:Spring-AOP通知和执行顺序?
java·开发语言·spring
番茄去哪了29 分钟前
Java基础面试题day02
java·开发语言·面向对象编程
xushichao198933 分钟前
C++中的工厂模式高级应用
开发语言·c++·算法
njsgcs34 分钟前
c# solidworks 折弯系数检查
开发语言·c#