一、一个游戏,前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(" "); } 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(" "); } 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(" "); } for(var a = -1;a < (h + 1 * h);a++){ document.write("*"); } document.write("<br />"); }