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>

实验结果截图:

相关推荐
wyzqhhhh8 小时前
前端常见的设计模式
前端·设计模式
IT_陈寒8 小时前
React 19重磅前瞻:10个性能优化技巧让你少写30%的useEffect代码
前端·人工智能·后端
陈皮话梅糖@8 小时前
Speckit和Claude 的初体验
开发语言·ide
屈冠成9 小时前
C语言数组:编辑世界的坚固桥梁
c语言·开发语言·算法
zzzyyy5389 小时前
STL简介
开发语言·c++
艾莉丝努力练剑9 小时前
【C++:继承】C++面向对象继承全面解析:派生类构造、多继承、菱形虚拟继承与设计模式实践
linux·开发语言·c++·人工智能·stl·1024程序员节
m0_748233649 小时前
C++开发中的常用设计模式:深入解析与应用场景
javascript·c++·设计模式
fruge9 小时前
TypeScript 基础类型与接口详解
javascript·ubuntu·typescript
报错小能手9 小时前
项目——基于C/S架构的预约系统平台(3)
linux·开发语言·笔记·学习·架构·1024程序员节
lsx2024069 小时前
jQuery Mobile 实例
开发语言