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>

实验结果截图:

相关推荐
夜晚回家4 小时前
Python 零基础入门 | 输入的数字为什么不能直接算
开发语言·python
时间的拾荒人4 小时前
Qt 事件机制全解析:从事件处理到事件过滤器
开发语言·qt·面试
于指尖飞舞4 小时前
java面试题总结
java·开发语言
yivifu5 小时前
中文古籍电子书注释集成
前端·javascript·python·beautifulsoup·epub
weixin_448290255 小时前
书庐开发实战教学
javascript·css·html
默_笙5 小时前
🛴 从散件到整机:DeepAgents 与 Agent 身上预留的那些"插槽"(前置介绍)
前端·javascript
zhangzeyuaaa6 小时前
深入理解 Ruby 运算符:本质、分类、坑点与重载实战
开发语言·前端·ruby
一木 之林6 小时前
DeepSeek Agent 开发(一)
开发语言·前端·javascript
朔北之忘 Clancy6 小时前
青少年软编等考七级题解目录
开发语言·c++·青少年编程·gesp·csp·信奥赛·noi
ss2736 小时前
AI全栈实战 | 3.2-01 Python 基础:四大数据容器怎么选,推导式为什么是 Pythonic 的灵魂
开发语言·人工智能·python