1
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>if练习1</title>
<script type="text/javascript">
/*
* 从键盘输入小明的期末成绩:
* 当成绩为100时,'奖励100元'
* 当成绩为[80-99]时,'奖励60元'
* 当成绩为[60-80]时,'奖励30元'
* 其他时,什么奖励也没有
*/
var score = prompt("请输入小明的期末成绩")
if (score==100) {
alert("奖励100元")
}
else if(score>79){
alert("奖励60元")
}
else if(score>59){
alert("奖励30元")
}
else{
alert("弟弟")
}
</script>
</head>
<body>
</body>
<html>
2
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>if练习2</title>
<script type="text/javascript">
/*
* 大家都知道,男大当婚,女大当嫁。那么女方家长要嫁女儿,当然要提出一定的条件:
* 高:185cm以上; 富:1200万以上; 帅:100以上;
* 如果这三个条件同时满足,则:'我一定要嫁给他'
* 如果三个条件有为真的情况,则:'嫁吧,比上不足,比下有余。'
* 如果三个条件都不满足,则:'不嫁!'
*/
var height = prompt("请输入身高")
var money = prompt("请输入财富,单位为万")
var smart = prompt("请输入颜值")
if (height>=185&&money>=1200&&smart>=100) {
alert("我一定要嫁给他")
}
else if (height>=185||money>=1200||smart>=100) {
alert("嫁吧,比上不足,比下有余。")
}
else {
alert("不嫁!")
}
</script>
</head>
<body>
</body>
<html>
3
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>if练习3</title>
<script type="text/javascript">
/*
* 编写程序,由键盘输入三个整数分别存入变量num1、num2、num3,
* 对他们进行排序,并且从小到大输出。
*/
var num1 = prompt("请输入第一个数:");
var num2 = prompt("请输入第二个数:");
var num3 = prompt("请输入第三个数:");
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>
4
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch练习1</title>
<script type="text/javascript">
/*
* 对于成绩大于等于60分的,输出'合格'。低于60分的,输出'不合格'
*/
var score = Number(prompt("请输入您的分数"))
if (score>=60) {
var score_ =true;
}else{
var score_ =false;
}
switch(score_){
case true:
alert("合格")
break
default:
alert("不合格")
}
</script>
<body>
</body>
<html>
5
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch练习2</title>
<script type="text/javascript">
/*
* 从键盘接收整数参数,如果该数为1-7,打印对应的星期,否则打印非法参数。
*/
var i = prompt("请输入1~7的整数")
i = parseInt(i)
switch(i)
{
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>
6
<!DOCTYPE html>
<html>
<head>
<title>while练习一</title>
<script type="text/javascript">
var i =0
var money=1000
while(true){
money=money+money*0.05
i++
if (money>5000) {
alert(i)
break
}
}
</script>
</head>
<body>
</body>
<html>
7
<!DOCTYPE html>
<html>
<head>
<title>while练习二</title>
<script type="text/javascript">
while(true){
var i = 0
var score = prompt("请输入分数")
if (score<=0||score>100) {
alert("您输入的分数有误,请重新输入")
continue
}
else if(score==100){
alert("奖励100元")
}
else if(score>=80){
alert("奖励70元")
}
else if(score>=60){
alert("奖励30元")
}
else{
alert("弟弟")
}
}
</script>
</head>
<body>
</body>
<html>
8
<!DOCTYPE html>
<html>
<head>
<title>for练习一</title>
<script type="text/javascript">
var j = 0
for (var i = 0; i < 100; i++) {
if (i % 2 != 0) {
j=j+i
}
}
alert(j)
</script>
</head>
<body>
</body>
<html>
9
<!DOCTYPE html>
<html>
<head>
<title>for练习二</title>
<script type="text/javascript">
var a = 0
var j = 0
for (var i = 0; i <= 100; i++) {
if (i % 7 == 0) {
a+=1;
j+=i;
}
}
alert("7的倍数个数有:"+a)
alert("总和为:"+j)
</script>
</head>
<body>
</body>
<html>
10
<!DOCTYPE html>
<html>
<head>
<title>for练习三</title>
<script type="text/javascript">
for(var i=1; i<999;i++){
var bai = parseInt(i/100);
var shi = parseInt(i%100/10);
var ge = parseInt(i%10)
if(bai**3+ shi**3 + ge**3 == i){
alert(i)
}
}
</script>
</head>
<body>
</body>
<html>