<!DOCTYPE html>
<html>
<head>
<title>if练习一</title>
<meta charset="utf-8">
<script type="text/javascript">
/*
* 从键盘输入小明的期末成绩:
* 当成绩为100时,'奖励一辆BMW'
* 当成绩为[80-99]时,'奖励一台iphone15s'
* 当成绩为[60-80]时,'奖励一本参考书'
* 其他时,什么奖励也没有
*/
var score = prompt('请输入小明的期末成绩(0——100:')
alert(score)
if(score == 100){
alert('奖励一辆BMW');
}
else if(score<100 && score>=80){
alert('奖励一台iphone15s');
}
else if(score<80 && 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">
/*
* 大家都知道,男大当婚,女大当嫁。那么女方家长要嫁女儿,当然要提出一定的条件:
* 高:180cm以上; 富:1000万以上; 帅:500以上;
* 如果这三个条件同时满足,则:'我一定要嫁给他'
* 如果三个条件有为真的情况,则:'嫁吧,比上不足,比下有余。'
* 如果三个条件都不满足,则:'不嫁!'
*/
var gao = prompt('请输入您的身高')
alert(gao)
var fu = prompt('请输入您的资产')
alert(fu)
var shuai = prompt('请输入您的颜值')
alert(shuai)
if(gao > 180 && fu>10000000 && shuai>500){
alert('我一定要嫁给他');
}
else if(gao > 180 || fu>10000000 || shuai>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">
/*
* 编写程序,由键盘输入三个整数分别存入变量num1、num2、num3,
* 对他们进行排序,并且从小到大输出。
*/
var num1 = parseInt(prompt('请输入您要输入的数字'))
var num2 = parseInt(prompt('请输入您要输入的数字'))
var num3 = parseInt(prompt('请输入您要输入的数字'))
if(num1>num2&&num2>num3){
var str = [num3,num2,num1]
alert(str);
}
else if(num1>num3&&num3>num2){
var str = [num2,num3,num1]
alert(str);
}
else if(num2>num1&&num1>num3){
var str = [num3,num1,num2]
alert(str);
}
else if (num2>num3&&num3>num1){
var str = [num1,num3,num2]
alert(str);
}
else if (num3>num2&&num2>num1){
var str = [num1,num2,num3]
alert(str);
}
else if (num3>num1&&num1>num2){
var str = [num2,num1,num3]
alert(str);
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch练习1</title>
<script type="text/javascript">
/*
* 对于成绩大于等于60分的,输出'合格'。低于60分的,输出'不合格'
*/
var score = parseInt(prompt('请输入您的分数'))
var a = score>=60
switch(a){
case true:
alert('合格')
break;
case false:
alert('不合格')
break;
}
</script>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch练习2</title>
<script type="text/javascript">
/*
* 从键盘接收整数参数,如果该数为1-7,打印对应的星期,否则打印非法参数。
*/
var today = parseInt(prompt('今天星期几'))
var i = (today <= 7 && today>=1)
switch(i){
case true:
alert('星期'+ today)
break;
case false:
alert('非法参数')
break;
}
</script>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript">
var a = 1000;
var b = 0;
while(a<=5000){
a=a*1.05;
b++
}
console.log(b);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript">
var num=prompt('请输入今天星期几');
switch(num){
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('非法参数');
break;
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript">
var i = 0
for (var z = 1;z<=100;z++){
if(z%2 != 0){
i += z
}
}
alert(i)
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript">
var num = [];
for(var i = 1;i<=100;i++){
if(i%7 == 0){
num.push(i);
}
}
a=num.length
alert(a);
var z = 0
for (var s=0;s<a;s++){
z += (num[s])
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript">
var num = [];
for (var i=100;i<1000;i++){
var a = parseInt(i/100)
var b = parseInt((i-a*100)/10)
var c = i%10
if ((a**3 + b**3 + c**3)==i){
num.push(i)
}
}
alert(num.length);
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript">
var i = prompt('请输入整数')
if (i<=1){
alert('这不是质数');
}
else if (i == 2){
alert('这是质数')
}
else{
for(var j = 2;j<i;j++){
if (i%j == 0){
alert('这不是质数')
break;
}
else{
alert('这是质数')
break;
}
}
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript">
var str=''
for(var i = 1;i<10;i++){
for(var j=1;j<10;j++){
str += (i +'*' +j+'='+(i*j)+' ')
}
str += '<br/>'
}
document.write(str)
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript">
for(var i=2;i<=100;i++){
for(var j=2;j<i;j++){
if(i%j==0){
break;
}
}
if(i<=j){
document.write(i+" ");
}
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="utf-8">
<script type="text/javascript">
var money = 1000;
var year = 0;
while(money <= 5000){
money *= 1.05;
year += 1;
}
document.write(year)
</script>
</head>
<body>
</body>
</html>