<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>if练习1</title>
<script type="text/javascript">
var score = prompt("请输入小明的期末成绩(0-100):");
if(score > 100 || score < 0 || isNaN(score)){
alert("输入错误");
}else{
if(score == 100){
alert("真棒~~~");
}else if(score >= 80){
alert("继续努力~~~");
}else if(score >= 60){
alert("加油·!");
}else{
alert("笨蛋~~~");
}
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>if练习2</title>
<script type="text/javascript">
var height = prompt("请输入你的身高(CM):");
var money = prompt("请输入你的财富(万):");
var face = prompt("请输入你的颜值(PX):");
if(height > 180 && money > 1000 && face > 500){
alert("我一定要嫁给他~~");
}else if(height > 180 || money > 1000 || face > 500){
alert("嫁吧,比上不足,比下有余。");
}else{
alert("不嫁。");
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>if练习3</title>
<script type="text/javascript">
var num1 = +prompt("请输入第一个数:");
var num2 = +prompt("请输入第二个数:");
var num3 = +prompt("请输入第三个数:");
alert(typeof num1);
if(num1 < num2 && num1 < num3){
if(num2 < num3){
alert(num1 +","+num2 + ","+num3);
}else{
alert(num1 +","+num3 + ","+num2);
}
}else if(num2 < num1 && num2 < num3){
if(num1 < num3){
alert(num2 +","+num1 + ","+num3);
}else{
alert(num2 +","+num3 + ","+num1);
}
}else{
if(num1 < num2){
alert(num3 +","+num1 + ","+num2);
}else{
alert(num3 +","+num2 + ","+num1);
}
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch练习1</title>
<script type="text/javascript">
var score=70;
switch(true){
case score >= 60 && score <=100:
alert("合格");
break;
case score < 60 && score >=0:
alert("不合格");
break;
default:
alert("不合法");
break;
}
</script>
<body>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>switch练习2</title>
<script type="text/javascript">
var today = +prompt("今天星期几?");
switch(today){
case 1:
alert('学语文');
break;//结束整个switch语句
case 2:
alert('学数学');
break;
case 3:
alert('学英语');
break;
case 4:
alert('学美术');
break;
case 5:
alert('学舞蹈');
break;
default:
alert('吃饭睡觉打豆豆');
break;
}
</script>
</head>
<body>
</body>
</html>
网友评论