【JavaScript】for循环小练习
1、输出1-100的和 1 var sum = 0 ; 2 for ( var i=1;i<=100;i++ ){ 3 sum = sum + i; 4 } 5 document.write(sum); 2、输出1-100奇数的和 1 var sum = 0 2 for ( var i=1;i<=100;i+=2 ){ 3 sum = sum+ i; 4 } 5 document.write(sum); 3、输出1-100偶数的和 1 var sum = 0 ; 2 for ( var i=2;i<=100;i+=2 ){ 3 sum = sum+ i; 4 } 5 document.write(sum); 4、打印99乘法口诀表 1 3 var num =0 ; 4 document.write("<table border='0' cellspacing='0' cellpadding='0'>" ); 5 for (var i=9;i>=1;i-- ){ //控制行 6 document.write("<tr>" ) 7 for (var j=1;j<=i;j++ ){ //控制列 8 9 document.write("<td>"+i+"*"+j+"="+i*j+"</td>" ); 10 } 11