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>

实验结果截图:

相关推荐
DeepModel13 小时前
通俗易懂讲透 Mini-Batch K-means
开发语言·人工智能·机器学习·kmeans·batch
虹科网络安全13 小时前
艾体宝洞察|NPM供应链攻击:复杂的多链加密货币攻擊渗透流行软件包
前端·npm·node.js
happy_baymax13 小时前
基于正弦波直接移相的PSFB控制方法
开发语言
傻啦嘿哟13 小时前
如何用 Python 拆分 Word 文件:高效分割大型文档的完整指南
开发语言·c#
高斯林.神犇13 小时前
五、注解方式管理bean
java·开发语言
hoiii18713 小时前
C# 读取 CSV/Excel 文件数据至 DataGridView
开发语言·c#·excel
xiaotao13113 小时前
01-编程基础与数学基石: 常用内置库
开发语言·人工智能·python
一只大袋鼠14 小时前
MySQL 进阶:聚集函数、分组、约束、多表查询
开发语言·数据库·mysql
nujnewnehc18 小时前
ps, ai, ae插件都可以用html和js开发了
前端·javascript
Jagger_21 小时前
整洁架构三连问:是什么,怎么做,为什么要用
前端