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>

实验结果截图:

相关推荐
Wenweno0o7 小时前
0基础Go语言Eino框架智能体实战-chatModel
开发语言·后端·golang
于慨7 小时前
Lambda 表达式、方法引用(Method Reference)语法
java·前端·servlet
石小石Orz7 小时前
油猴脚本实现生产环境加载本地qiankun子应用
前端·架构
从前慢丶7 小时前
前端交互规范(Web 端)
前端
@yanyu6668 小时前
07-引入element布局及spring boot完善后端
javascript·vue.js·spring boot
CHU7290358 小时前
便捷约玩,沉浸推理:线上剧本杀APP功能版块设计详解
前端·小程序
chenjingming6668 小时前
jmeter线程组设置以及串行和并行设置
java·开发语言·jmeter
GISer_Jing8 小时前
Page-agent MCP结构
前端·人工智能
王霸天8 小时前
💥别再抄网上的Scale缩放代码了!50行源码教你写一个永不翻车的大屏适配
前端·vue.js·数据可视化
小领航8 小时前
用 Three.js + Vue 3 打造炫酷的 3D 行政地图可视化组件
前端·github