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>

实验结果截图:

相关推荐
anOnion13 分钟前
构建无障碍组件之Carousel Pattern
前端·html·交互设计
ssshooter21 分钟前
Tauri 2 iOS 开发避坑指南:文件保存、Dialog 和 Documents 目录的那些坑
前端·后端·ios
比昨天多敲两行1 小时前
C++ 二叉搜索树
开发语言·c++·算法
Можно1 小时前
深入理解 ES6 Proxy:与 Object.defineProperty 的全面对比
前端·javascript·vue.js
Birdy_x1 小时前
接口自动化项目实战(1):requests请求封装
开发语言·前端·python
海海不瞌睡(捏捏王子)2 小时前
C++ 知识点概要
开发语言·c++
桌面运维家2 小时前
VLAN配置进阶:抑制广播风暴,提升网络效率
开发语言·网络·php
天天向上10243 小时前
vue el-table实现拖拽排序
前端·javascript·vue.js
一轮弯弯的明月3 小时前
Python基础-速通秘籍(下)
开发语言·笔记·python·学习
西西学代码3 小时前
Flutter---回调函数
开发语言·javascript·flutter