1、建立测试数组;
2、用for循环挨个测试;
3、进行条件判断,并输出判断结果到HTML
4、在for循环内输出分隔线
<script type="text/javascript"> var xs=[2001,2002,2003,2004,2005,2008,2020,3000,4000]; for (var i = 8; i >= 0; i--) { x = xs[i]; if(x%4 != 0){ document.write(x+'不是闰年'); }else if(x%400 == 0){ document.write(x+'是闰年'); }else if(x%100 == 0){ document.write(x+'不是闰年'); }else{ document.write(x+'是闰年'); } document.write('<hr>'); } var grades=[10,20,30,40,50,60,70,80,90,100]; for (var i = 9; i >= 0; i--) { grade = grades[i]; if(grade<60){ document.write('你考试-'+grade+'-分,不及格!!!'); }else if(grade<70){ document.write('你考试-'+grade+'-分,继续加油!'); }else if(grade<90){ document.write('你考试-'+grade+'-分,成绩良好'); }else if(grade<100){ document.write('你考试-'+grade+'-分,成绩优秀,注意休息'); }else{ document.write('你考试-'+grade+'-分,满分,没作弊吧?'); } document.write('<hr>'); } </script>
==============================
执行效果
======
以下是小结:
1、用+号连接变量名和字符串后,就可以在document.write()或alert()中输出变量值接字符串;
2、sublime的js的for循环默认写法,是从尾到头遍历的。