当前位置:网站首页>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
边栏推荐
- MFC实现资源单独Dll实现
- Graphics. Fromimage reports an error "graphics object cannot be created from an image that has an indexed pixel..."
- Uniapp wechat sharing
- Laravel routing settings
- C#测试调用PaddleSharp模块识别图片文字
- 相机成像+单应性变换+相机标定+立体校正
- 如果我是pm之 演出电影vr购票展示
- Study notes: unity customsrp-13-colorgrading
- Log introduction and building web application
- Three 之 three.js (webgl)旋转属性函数的简单整理,以及基于此实现绕轴旋转的简单案例
猜你喜欢
领域驱动模型DDD(三)——使用Saga管理事务
If I am PM's performance, movie VR ticket purchase display
2021-09-23
MFC implementation resources are implemented separately by DLL
2021-11-08
My old programmer's perception of the dangers and opportunities of the times?
Devops life cycle, all you want to know is here!
phphphphphphphp
2021 年 25 大 DevOps 工具(下)
JSP -- Introduction to JSP
随机推荐
Log introduction and building web application
了解 DevOps,必读这十本书!
JS Array常见方法
Laravel [view]
d. TS --- for more detailed knowledge, please refer to the introduction on the official website (chapter of declaration document)
好的测试数据管理,到底要怎么做?
What are the reasons for the failure of digital transformation?
Source code analysis of how to use jump table in redis
点击添加按钮--出现一个框框(类似于添加学习经历-本科-研究生)
Qingdao agile tour, coming!
日志简介和构建web应用
JVM memory and memory overflow exceptions (personal summary)
【openh264】cmake: msopenh264-static
Open source rule engine - Ice: dedicated to solving flexible and complex hard coding problems
selenium預先加載cookie的必要性
Three 之 three.js (webgl)模型的删除/场景的清空/内存的释放 的简单整理
Error handling mechanism of the strongest egg framework in history
Five key technologies to improve the devsecops framework
PIP free export with path (@ file: / / /) notes
Asynchronous iterator & asynchronous generator & asynchronous context manager