当前位置:网站首页>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
边栏推荐
- 使用 Kears 实现ResNet-34 CNN
- Log introduction and building web application
- selenium預先加載cookie的必要性
- C test calls the paddlesharp module to recognize pictures and words
- [untitled]
- 2021-10-12
- Mariadb的半同步复制
- Excel 2016 打开文件第一次打不开,有时空白,有时很慢要打开第二次才行
- Laravel routing job
- How to add beautiful code blocks in word | a very complete method to sort out and compare
猜你喜欢

Cloud computing and cloud native architecture design of openshift

Uncle wolf is looking for a translator -- Plato -- ongoing translation

CPT 104_TTL 09

2021 年 25 大 DevOps 工具(下)

Excel 2016 cannot open the file for the first time. Sometimes it is blank and sometimes it is very slow. You have to open it for the second time

Uniapp wechat sharing

SQLyog的基本使用

引入精益管理方式,需要提前做到这九点

领域驱动模型DDD(三)——使用Saga管理事务

(十一)vscode代码格式化配置
随机推荐
Solve the problem of JS calculation accuracy
4 most common automated test challenges and Countermeasures
Publish your own wheel - pypi packaging upload practice
狼叔来找翻译人员了--plato--持续翻译中.....
MySQL series - install MySQL 5.6.27 on Linux and solve common problems
双击.jar包无法运行解决方法
Camera imaging + homography transformation + camera calibration + stereo correction
JSP-----JSP简介
Implementation of resnet-34 CNN with kears
MFC实现资源单独Dll实现
好的测试数据管理,到底要怎么做?
Log introduction and building web application
My old programmer's perception of the dangers and opportunities of the times?
d. TS --- for more detailed knowledge, please refer to the introduction on the official website (chapter of declaration document)
How to realize adaptive layout
The prefix of static of egg can be modified, including boots
selenium预先加载cookie的必要性
学习笔记:Unity CustomSRP-12-HDR
Project manager's thinking mode worth trying: project success equation
如果我是pm之 演出电影vr购票展示