1. 程式人生 > >0511JS綜合練習

0511JS綜合練習

現在 rom while += else div nbsp 遊戲 write

一、一個遊戲,前20關是每一

關自身的分數,
21-30關每一關是10分,
31-40關,每一關是20分,
41-49關,每一關是30分,
50關,是100分,
輸入你現在闖到的關卡數,求你現在擁有的分數.

var guan = prompt("請輸入你現在闖到的關卡數");
var fen = 0;
while(guan > 50){
guan = prompt("請輸入正確的的關卡數");
}
if (guan <= 20) {
for(var gs = 0;gs <= guan; gs++){
fen += gs;
}alert(fen);
} else if(guan <= 30){
for(var gs = 0;gs <= 20; gs++){
fen += gs;
}
for(var gs = 21;gs <= guan; gs++){
fen += 10;
}
alert(fen);
} else if(guan <= 40){
for(var gs = 0;gs <= 20; gs++){
fen += gs;
}
for(var gs = 21;gs <= 30; gs++){
fen += 10;
}
for(var gs = 31;gs <= guan; gs++){
fen += 20;
}
alert(fen);
} else if(guan < 50){
for(var gs = 0;gs <= 20; gs++){
fen += gs;
}
for(var gs = 21;gs <= 30; gs++){
fen += 10;
}
for(var gs = 31;gs <= 40; gs++){
fen += 20;
}
for(var gs = 41;gs <= guan; gs++){
fen += 30;
}
alert(fen);
} else if(guan == 50){
for(var gs = 0;gs <= 20; gs++){
fen += gs;
}
for(var gs = 21;gs <= 30; gs++){
fen += 10;
}
for(var gs = 31;gs <= 40; gs++){
fen += 20;
}
for(var gs = 41;gs < 50; gs++){
fen += 30;
}
fen += 100;
alert(fen);
}

二、打印三角形

*
**
***
****

*
**
***
****

****
***
**
*


****
***
**
*


*
***
*****
*******

for(var h = 0;h < 4; h++){
for(var a = 0;a <=h; a++){
document.write("*");
}
document.write("<br />");
}
document.write("<br />");
for(var h = 0;h < 4; h++){
for(var a = 3;a >h; a--){
document.write("&ensp;");
}
for(var a = 0;a <=h; a++){
document.write("*");
}
document.write("<br />");
}
document.write("<br />");
for(var h = 0;h < 4; h++){
for(var a = 0;a <h; a++){
document.write("&ensp;");
}
for(var a = 4;a >h; a--){
document.write("*");
}
document.write("<br />");
}
document.write("<br />");
for(var h = 0;h < 4; h++){
for(var a = 4;a >h; a--){
document.write("*");
}
document.write("<br />");
}
document.write("<br />");
for(var h = 0; h < 4;h++){
for(var a = 3;a > h;a--){
document.write("&ensp;");
}
for(var a = -1;a < (h + 1 * h);a++){
document.write("*");
}
document.write("<br />");
}

0511JS綜合練習