本文主要是介绍javascript基础代码练习之超速罚款,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
<!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>
实验结果截图:
这篇关于javascript基础代码练习之超速罚款的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!