练习:
题目:
从==键盘输入==小明的期末成绩:
- 当成绩为100时,奖励一辆宝马
- 当成绩为[80-99]时,奖励一台iphone15s
- 当成绩为[60-80]时,‘奖励一本参考书'
- 其他时,什么奖励也没有
<!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>Document</title>
<script>
var score = prompt("请输入小明的期末成绩")
if (score == 100)
{
alert("给你一辆宝马");
}
else if(score >= 80 && score <= 99)
{
alert("奖励一台iphone15s");
}
else if (score >= 60 && score <= 80)
{
alert("奖励一本参考书");
}
else
{
alert("欠干的玩意");
}
</script>
</head>
<body>
</body>
</html>
学习总结:
1、新函数(prompt)
- prompt( )可以弹出一个提示框,该提示框中会带有一个文本框
- 用户可以在文本框中输入一段内容,该函数需要一个字符串作为参数
- 该字符串将会作为提示框的提示文字
- prompt( )返回值只能是string类型
<!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>Document</title>
<script>
var score = prompt("请输入小明的期末成绩")
alert(score)
</script>
</head>
<body>
</body>
</html>
2、注意:
else 后面不需要条件
题目二:
大家都知道,男大当婚,女大当嫁。那么女方家长要嫁女儿,当然要提出一定的条件:==键盘输入==
高:180cm以上;富:1000万以上;帅:6以上;
如果这三个条件同时满足,则:‘我一定要嫁给他"
如果三个条件有为真的情况,则:‘嫁吧,比上不足,比下有余。"
如果三个条件都不满足,则:'不嫁!'
<!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>Document</title>
<script>
var tall = prompt("请输入身高cm")
var rich = prompt("请输入你的资产w")
var bueatifull = prompt("输入你的颜值(0~~~10)")
if (tall >= 180 && rich>=1000 && bueatifull >= 6)
{
alert("我一定要娶给她");
}
else if(tall < 180 && rich < 1000 && bueatifull >= 6)
{
alert("嫁吧,比上不足,比下有余。");
}
else if(tall < 180 && rich >= 1000 && bueatifull < 6)
{
alert("嫁吧,比上不足,比下有余。");
}
else if(tall >= 180 && rich < 1000 && bueatifull < 6)
{
alert("嫁吧,比上不足,比下有余。");
}
else
{
alert("不嫁");
}
</script>
</head>
<body>
</body>
</html>
题目三:
编写程序,由==键盘输入==:
三个整数分别存入变量num1.num2. num3,
对他们进行排序,并且从小到大输出。
<!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>Document</title>
<script>
var num1 = +prompt("请输入数字1 ")
var num2 = +prompt("请输入数字2 ")
var num3 = prompt("请输入数字3 ")
if (num1 > num2 && num1 > num3 )
{
if(num1 > num3 && num2 > num3)
{
alert("num1 > num2 > num3 ");
}
else if(num1 > num2 && num3 >num2 )
{
alert("num1 > num3 >num2");
}
}
else if(num2 > num3 && num2 >num1)
{
if(num1 > num3 && num2 > num3)
{
alert("Num2 > Num1 > Num3 ");
}
else if(num2 > num3 && num3 >num1 )
{
alert("Num2 > Num3 > Num1");
}
}
else if(num3 > num1 && num3 > num2)//num3 最大
{
if(num3 > num2 && num1 > num2)
{
alert("Num3 > Num1 > Num2");
}
else if(num3 > num1 && num2 >num1 )
{
alert("Num3 > Num2 > Num1");
}
}
else{
alert("啥也不是")
}
</script>
</head>
<body>
</body>
</html>