流程控制分支结构导读
![在这里插入图片描述](https://img-blog.csdnimg.cn/4a1236cd97054027bbf74f3d0a3c5562.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NjE4NTIx,size_16,color_FFFFFF,t_70) ![在这里插入图片描述](https://img-blog.csdnimg.cn/dfd895528e284f25a9e41a0846f5013c.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NjE4NTIx,size_16,color_FFFFFF,t_70)
if案例
![在这里插入图片描述](https://img-blog.csdnimg.cn/3331123ee89443bca15541ac869d4d4f.png)
<script>
var age = prompt('请输入年龄:');
if(age>=18){
alert('可以进入');
}
</script>
![在这里插入图片描述](https://img-blog.csdnimg.cn/f8215d3419414e3ba0bc0da05c427313.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NjE4NTIx,size_16,color_FFFFFF,t_70)
三元表达式
条件表达式 ?表达式1 :表达式2 ![在这里插入图片描述](https://img-blog.csdnimg.cn/9e8a566a44d146368dac0d2c7807885f.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NjE4NTIx,size_16,color_FFFFFF,t_70)
switch
![在这里插入图片描述](https://img-blog.csdnimg.cn/f38c229d94584cabbc79e385adf2f052.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NjE4NTIx,size_16,color_FFFFFF,t_70)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>if</title>
<script>
switch(2){
case 1:
console.log('这是1');
break;
case 2:
console.log('这是2');
break;
case 3:
console.log('这是3');
break;
default:
console.log('没有结果');
}
</script>
</head>
<body>
</body>
</html>
买水果案例
![在这里插入图片描述](https://img-blog.csdnimg.cn/75de870aea204f83aa4c77d1face96d0.png)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>水果</title>
<script>
var fruit = prompt('please input the type of the fruit:');
switch(fruit){
case 'apple':
alert('$3.5');
break;
case 'banana':
alert('$4.0');
break;
case 'peach':
alert('$2.7');
break;
default:
alert('sold out');
}
</script>
</head>
<body>
</body>
</html>
switch与if区别
![在这里插入图片描述](https://img-blog.csdnimg.cn/20a0ab668a1f463d9c50a87f312ee17d.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3FxXzQ1NjE4NTIx,size_16,color_FFFFFF,t_70)
|