当前位置:网站首页>Simple and basic use of switch and if
Simple and basic use of switch and if
2022-04-23 05:26:00 【Courtesy.】
use switch Methods to determine the age group
Generally, when judging relatively complex conditions, you can use IF Sentence to judge
default: When all parameters do not match Just print default What to do
1.switch Method
<script>
function message(age) {
let msg = " ",
switch (true) {
// here switch(2>1) It can also be executed normally , because 2>1 It's true
case age > 60 :
msg = " The elderly ";
break; //break Exit after execution , If it doesn't match Just move on to the next option And so on Execute until the corresponding is matched
case age > 40:
msg = " middle-aged ";
break;
case age > 20:
msg = " youth ";
break;
}
return msg; //return Return to the age of msg
}
console.log(message(67)); // Printout 67 The age group you belong to at the age of
</script>
1.if Method
function message(age) {
let msg = " ",
if (age > 60) {
msg = " The elderly ";
} else if (age > 40) {
msg = " middle-aged ";
}else if (age > 20) {
msg = " youth ";
}
return msg;
}
console.log(message(67)); // Printout 67 The age group you belong to at the age of
版权声明
本文为[Courtesy.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220544339254.html
边栏推荐
- 改进DevSecOps框架的 5 大关键技术
- Nécessité de précharger les cookies dans le sélénium
- When is it appropriate for automated testing? (bottom)
- 狼叔来找翻译人员了--plato--持续翻译中.....
- App Store年交易额100万美元只缴15%佣金,中小开发者心里很矛盾
- 4 most common automated test challenges and Countermeasures
- Solution of how to log in with mobile phone verification code in wireless network
- My old programmer's perception of the dangers and opportunities of the times?
- Three of three JS (WEB GL) model deletion / scene emptying / simple sorting of memory release
- 看板快速启动指南
猜你喜欢

How to add beautiful code blocks in word | a very complete method to sort out and compare

Use of ES6 array

mariadb数据库的主从复制

跨域CORS的情缘~

selenium預先加載cookie的必要性

SQLyog的基本使用

Modèle axé sur le domaine DDD (III) - gestion des transactions à l'aide de Saga

Project manager's thinking mode worth trying: project success equation

Open source rule engine - Ice: dedicated to solving flexible and complex hard coding problems

Three 之 three.js (webgl)旋转属性函数的简单整理,以及基于此实现绕轴旋转的简单案例
随机推荐
PIP free export with path (@ file: / / /) notes
Project manager's thinking mode worth trying: project success equation
Mariadb的半同步复制
Laravel routing job
开源规则引擎——ice:致力于解决灵活繁复的硬编码问题
Blender程序化地形制作
2021-10-08
了解 DevOps,必读这十本书!
Laravel implements the Holy Grail model with template inheritance
Kanban Quick Start Guide
JS Array常见方法
Source code analysis of how to use jump table in redis
Data management of basic operation of mairadb database
Interpretation of common SQL statements
C#测试调用PaddleSharp模块识别图片文字
项目经理值得一试的思维方式:项目成功方程式
CORS and proxy (づ  ̄ 3  ̄) in egg ~ the process of stepping on the pit and filling the pit ~ tot~
Parsing of string class intern() method
2021-11-08
使用 Kears 实现ResNet-34 CNN