Python全系列 教程
3567个小节阅读:5931.5k
目录
鸿蒙应用开发
C语言快速入门
JAVA全系列 教程
面向对象的程序设计语言
Python全系列 教程
Python3.x版本,未来主流的版本
人工智能 教程
顺势而为,AI创新未来
大厂算法 教程
算法,程序员自我提升必经之路
C++ 教程
一门通用计算机编程语言
微服务 教程
目前业界流行的框架组合
web前端全系列 教程
通向WEB技术世界的钥匙
大数据全系列 教程
站在云端操控万千数据
AIGC全能工具班
A A
White Night
if代码块后面,还可以跟一个else代码块,表示不满足条件时,所要执行的代码。
xxxxxxxxxx
if (m === 3) {
// 满足条件时,执行的语句
} else {
// 不满足条件时,执行的语句
}
对同一个变量进行多次判断时,多个if...else语句可以连写在一起。
xxxxxxxxxx
if (m === 0) {
// ...
} else if (m === 1) {
// ...
} else if (m === 2) {
// ...
} else {
// ...
}
xxxxxxxxxx
var eat = true;
var food = "猪肉炖粉条";
if (eat) {
if (food == "双椒鱼头") {
console.log('双椒鱼头');
}else{
console.log("猪肉炖粉条");
}
} else {
console.log('不吃了');
}
else代码块总是与离自己最近的那个if语句配对。
实时效果反馈
1.下列条件语句中,横线处应填写代码是 :
xxxxxxxxxx
var eat = true;
var food = "猪肉炖粉条";
if (eat) {
if (food ___ "双椒鱼头") {
console.log('双椒鱼头'); // 打印双椒鱼头
}else{
console.log("猪肉炖粉条");
}
} else {
console.log('不吃了');
}
A =
B ==
C ===
D !=
2. 下列代码运行结果是:
xxxxxxxxxx
var day = 3;
if(day === 1){
console.log("再向虎山行");
}else if(day === 2){
console.log("路漫漫");
}else if(day === 3){
console.log("野茫茫");
}else if(day === 4){
console.log("曙光在前头");
}else if(day === 5){
console.log("归心似箭");
}else{
console.log("胜利大逃亡");
}
A 再向虎山行
B 野茫茫
C 曙光在前头
D 胜利大逃亡
答案
1=>D 2=>B