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>

实验结果截图:

相关推荐
总有刁民想爱朕ha8 分钟前
零基础Python开发「图片批量转MP4视频」工具,本地离线、免费无水印
开发语言·python·音视频
l1t14 分钟前
测试DuckDB luajit插件读取本地通达信文件
开发语言·数据库·duckdb
捧 花23 分钟前
FastAPI 基础语法:从一个完整接口理解 Web API 的设计
前端·python·fastapi·middleware
Hilaku30 分钟前
一行 CSS 新特性干掉 20 行 JavaScript ?
前端·javascript·程序员
老一岁30 分钟前
c问题总结(2)
c语言·开发语言
Ming_studying31 分钟前
Python批量压缩图片:支持JPG_PNG_WebP、尺寸限制与CSV报告
开发语言·图像处理·python·pillow·图片压缩
风月说与山鬼35 分钟前
JS闭包详解
开发语言·javascript
何以解忧,唯有..36 分钟前
Python协程详解:从生成器到async/await的完整指南
开发语言·python
奶茶树41 分钟前
【C++】13. C++11新特性【上】
c语言·开发语言·c++·git·github
JarvanMo43 分钟前
AI 写代码暴增 161 倍,移动开发有没有变得更差?
前端