leap year calculator code javascript code example

Example 1: js leap year calculator

// https://www.mathsisfun.com/leap-years.html 
function isLeapYear(year) {
 
    if(year % 400 === 0){
        return ("yes");
    } if(year % 100 === 0){
        return ("no");
    } if (year % 4 === 0){
        return ("yes");
    } else {
        return ("no");
    }
    

}


isLeap(2024);

Example 2: js leap year calculator

// https://www.mathsisfun.com/leap-years.html 
function isLeapYear(year) { 

    if(year % 400 === 0){
        return (year + " is a leap year.");
    } if(year % 100 === 0){
        if(year % 400 === 0){
            return (year + " is a leap year.");
        } else {
          return (year + " is not a leap year.");
        }
    } if (year % 4 === 0){
        if(year % 100 === 0){
           return (year + " is not a leap year.");
        } else {
        return (year + " is a leap year.");
        }
    } else {
        return (year + " is not a leap year.");
    }

}

// leap year
// isLeap(2024);

// not leap year 
// isLeap(1930);