js 习题
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 5 <title></title> 6 <meta charset="utf-8" /> 7 </head> 8 <body> 9 <script> 10 var a = prompt("请输入名字", ""); 11 document.write(a); 12 </script> 13 14 <script>//输出个位 十位 百位 千位 15 var a = 1234; 16 var qianwei = a / 1000; 17 var baiwei = a % 1000 / 100; 18 var shiwei = a % 1000 % 100 / 10; 19 var gewei = a % 1000 % 100 % 10; 20 document.write(a + "<br/>"); 21 document.write(parseInt(qianwei)+"<br/>"); 22 document.write(parseInt(baiwei) + "<br/>"); 23 document.write(parseInt(shiwei) + "<br/>"); 24 document.write(gewei + "<br/>"); 25 </script> 26 27 <script> //bim指数 28 var tz = 110; 29 var sg = 170; 30 var bmi = tz / (sg * sg); 31 if (bmi < 18.5) { 32 alert("偏瘦"); 33 }else if(bmi<=23.9){ 34 alert("正常"); 35 } else if (bmi < 27.9) { 36 alert("偏胖"); 37 } 38 </script> 39 <script>//韩信点兵 40 for (i = 100; i <= 200;i++){ 41 if (i % 3 == 1) { 42 if(i%5==2){ 43 if(i%7==5){ 44 document.write("韩信点兵 "+i+"<br/>"); 45 } 46 } 47 } 48 } 49 </script> 50 <script> //水仙花 51 var baiwei, shiwei, gewei; 52 for (i = 100; i < 1000;i++){ 53 //huoqu 54 baiwei = parseInt(i / 100); 55 shiwei = parseInt(i % 100 / 10); 56 gewei = parseInt(i % 100 % 10); 57 if (Math.pow(baiwei, 3) + Math.pow(shiwei,3) + Math.pow(gewei ,3) == i) { 58 document.write("水仙花 "+i+"<br/>"); 59 } 60 } 61 </script> 62 <script> //鸡翁百鸡 63 var z; 64 for (x = 1; x < 20;x++){ 65 for (y = 1; y < 25;y++){ 66 z = 100 - x - y; 67 if(z%3==0&&x+y+z==100&&5*x+3*y+z/3==100){ 68 document.write("公鸡:"+x+"<br/>"+"母鸡:"+y+"<br/>"+"小鸡"+z+"<br/>"); 69 } 70 } 71 } 72 </script> 73 <script> //高斯求和 74 var a = new Array(100); 75 for (i = 0; i < a.length;i++){ 76 a[i] = i + 1; 77 } 78 var sum=0; 79 for (i = 0; i < a.length / 2; i++){ 80 sum += a[i] + a[a.length - (i + 1)] 81 } 82 document.write(sum); 83 </script> 84 85 </body> 86 </html>