Blogger Information
Blog 34
fans 0
comment 0
visits 39175
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
js基础——第五期线上——2019-3-25
黄健的博客
Original
716 people have browsed it

判断是否是闰年:条件1:年份必须要能被4整除,条件2:年份不能是整百数,条件3:年份是400的倍数

    

    当条件1和条件2同时成立时,就肯定是闰年,所以条件1和条件2之间为“与”的关系。

    如果条件1和条件2不能同时成立,但如果条件3能成立,则仍然是闰年。所以条件3与前2项为“或”的关系。

function isLeapYear(year) {
    var cond1 = year % 4 == 0;  
    var cond2 = year % 100 != 0;  
    var cond3 = year % 400 ==0; 
    var cond = cond1 && cond2 || cond3;
    if(cond) {
        console.log(year + "是闰年");
        return ;
    } else {
        console.log(year + "不是闰年");
        return ;
    }
}

var arr=[2000,400,5016,2018,2010,1998];
for( var i=0;i<arr.length;i++ ){
    isLeapYear(arr[i]);
}


给学生划分等级:

    var fen = 50;
    if(fen<60){
    console.log( "不及格“ );
    }else if(fen < 70){
     console.log( "及格“ );
}else if( fen< 79){
    console.log( "良“ );
}else if( fen< 89){
    console.log( "良好“ );
}else if(fen<=100){
    console.log( "优秀“ );
}


总结:学习了js基础知识,和条件判断语句,满足条件给出相应的反应。

Correction status:Uncorrected

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