if循環(huán)
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>if練習(xí)1</title>
<script type="text/javascript">
/*
* 從鍵盤輸入小明的期末成績:
* 當(dāng)成績?yōu)?00時,'獎勵一輛BMW'
* 當(dāng)成績?yōu)閇80-99]時,'獎勵一臺iphone15s'
* 當(dāng)成績?yōu)閇60-80]時,'獎勵一本參考書'
* 其他時,什么獎勵也沒有
*/
var score=prompt('請輸入期末成績')
if (score =='100') {
alert('獎勵一輛BMW');
}
else if(score>='80'&&score<='99') {
alert('獎勵一臺iphone15s');
}
else if(score>='60'&&score<'80'){
alert('獎勵一本參考書');
}
else{
alert('什么也沒有');
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>if練習(xí)2</title>
<script type="text/javascript">
/*
* 大家都知道,男大當(dāng)婚,女大當(dāng)嫁。那么女方家長要嫁女兒,當(dāng)然要提出一定的條件:
* 高:180cm以上; 富:1000萬以上; 帥:500以上;
* 如果這三個條件同時滿足,則:'我一定要嫁給他'
* 如果三個條件有為真的情況,則:'嫁吧,比上不足,比下有余。'
* 如果三個條件都不滿足,則:'不嫁!'
*/
var g=prompt('請輸入嫁女兒的身高條件');
var f=prompt('請輸入嫁女兒的富條件');
var s=prompt('請輸入嫁女兒的帥條件');
if (g>='180' && f>='1000' && s>='500') {
alert('我一定要嫁給他');
}
else if (g>='180' || f>='1000' || s>='500') {
alert('嫁吧,比上不足,比下有余');
}
else{
alert('不嫁');
}
</script>
</head>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>if練習(xí)3</title>
<script type="text/javascript">
/*
* 編寫程序,由鍵盤輸入三個整數(shù)分別存入變量num1、num2、num3,
* 對他們進行排序,并且從小到大輸出。
*/
// var num1=prompt('請輸入一個整數(shù):')
// var num2=prompt('請輸入一個整數(shù):')
// var num3=prompt('請輸入一個整數(shù):')
var num1 = +prompt('第一個數(shù)');
var num2 = +prompt('第二個數(shù)');
var num3 = +prompt('第三個數(shù)');
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>
switch循環(huán)
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch練習(xí)1</title>
<script type="text/javascript">
/*
* 對于成績大于等于60分的,輸出'合格'。低于60分的,輸出'不合格'
*/
var score = prompt('分?jǐn)?shù)');
var a = score % 10;
switch (a){
case 6:
alert('合格');
break;
case 7:
alert('合格');
break;
case 8:
alert('合格');
break;
case 9:
alert('合格');
break;
case 10:
alert('合格');
break;
default:
alert('不合格');
}
</script>
<body>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>switch練習(xí)2</title>
<script type="text/javascript">
/*
* 從鍵盤接收整數(shù)參數(shù),如果該數(shù)為1-7,打印對應(yīng)的星期,否則打印非法參數(shù)。
*/
var int = prompt('請輸入整數(shù)(1-7):');
switch (int){
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('非法參數(shù)');
}
</script>
<body>
</body>
</html>