分支语句练习
if-1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>if练习1</title>
<script type="text/javascript">
var a = true;
while (a == true){
score = prompt('请输入小明的成绩')
score = Number(score)
if(score >= 0 && score <= 100){
if (score == 100){
alert('奖励一辆BMW');
break
}
else if (score > 80 && score <= 99){
alert("奖励一台iphone15s");
break
}
else if (score > 60 && score <= 80){
alert("奖励一本参考书");
break
}
else{
alert("什么奖励也没有");
break
}
}
else{
alert('只能输入1-100的数字');
}
}
</script>
</head>
<body>
</body>
</html>
if-2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>if练习2</title>
<script type="text/javascript">
alert("请男方输入自己的条件;")
height = Number(prompt("请输入身高:"));
console.log(typeof height);
money = Number(prompt("请输入存款:"));
var a = true;
while (a == true){
face = Number(prompt("颜值分为1-1000,请输入正确的数字\n请输入颜值分:"));
if(face >= 1 && face <= 1000){
alert("输入完成,请等待!")
break
}
else{
alert("颜值分为1-1000,请输入正确的数字");
}
}
alert("女方回应;");
if (height >= 180 && money >=10000000 && face >= 500){
alert("我一定要嫁给他;")
}
else if (height >= 180 || money >=10000000 || face >= 500){
alert("嫁吧,比上不足,比下有余。")
}
else{
alert("不嫁!")
}
</script>
</head>
<body>
</body>
</html>
if-3
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>if练习3</title>
<script type="text/javascript">
var arr = [];
alert("现在请你输入三个数字,我将会将它们从小到大输出;");
num1 = Number(prompt("请输入第一个数字:"));
arr.push(num1);
num2 = Number(prompt("请输入第二个数字:"));
if (num1 <= num2){
arr.push(num2);
var num1_2 = true;
}else{
arr.unshift(num2);
var num1_2 = false;
}
num3 = Number(prompt("请输入第三个数字:"));
if (num1_2 == true){
if (num3 <= num1){
arr.unshift(num3);
}
else if (num3 >= num2){
arr.push(num3);
}
else{
arr.splice(1,0,num3)
}
}
else{
if (num3 <= num2){
arr.unshift(num3);
}
else if (num3 >= num1){
arr.push(num3);
}
else{
arr.splice(1,0,num3)
}
}
alert(arr);
</script>
</head>
<body>
</body>
</html>
switch-1
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch练习1</title>
<script type="text/javascript">
var score = Number(prompt("去请输入分数:"))
if (score >= 60){
var score_ = true;
}else{
var score_ = true;
}
switch(score_){
case true:
alert("合格");
break
case false:
alert("不合格");
break
}
</script>
<body>
</body>
</html>
switch-2
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch练习2</title>
<script type="text/javascript">
week = Number(prompt("请输入一个整数:"))
switch(week){
case 1:
alert("星期一;");
break
case 2:
alert("星期二;");
break
case 3:
alert("星期三;");
break
case 4:
alert("星期四;");
break
case 5:
alert("星期五;");
break
case 6:
alert("星期六;");
break
case 7:
alert("星期七;");
break
default:
alert("这是一个非法参数")
}
</script>
<body>
</body>
</html>