Blogger Information
Blog 13
fans 0
comment 0
visits 12167
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js成绩和闰年判断小案例3.25作业
小毛的博客
Original
665 people have browsed it

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>

==============================

执行效果

QQ截图20190325224329.png

======

以下是小结:

1、用+号连接变量名和字符串后,就可以在document.write()或alert()中输出变量值接字符串;

2、sublime的js的for循环默认写法,是从尾到头遍历的。


Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post