Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

leap year condition in javascript

//Easiest Leap-year condition
function isLeapyear(year){
    if(year%4==0  ||  year%400==0   &&   year%1000!=0){
        return true;
    }
    else{
        return false;
    }
}


const my_year = isLeapyear(1999);  //Tip: 2000 is a leap year.

console.log('My year is', my_year );
Comment

javascript leap year

function isLeapYear(year){
	if(year % 400 === 0 && year % 4 === 0){
      return true
    } else {
      return false
    }
}
Comment

Leap year function javascript

function isLeapYear(year) {
    if (year % 4 == 0) {
        console.log("leap year")
    } else {
        console.log("Not a leap year")
    }
}
var myYear = 2020;
isLeapYear(myYear)
// Output:leap year
Comment

get days in leap year javascript

You can find the number of days using the simple leap year algorithem:
In the Gregorian calendar three criteria must be taken into account to identify 
leap years: The year can be evenly divided by 4; If the year can be evenly 
divided by 100, it is NOT a leap year, unless; The year is also evenly divisible
by 400. Then it is a leap year.
function daysInYear(year) {
    return ((year % 4 === 0 && year % 100 > 0) || year %400 == 0) ? 366 : 365;
}
console.log(daysInYear(2016));
console.log(daysInYear(2017));
Comment

javascript Program to check if a given year is leap year

<script>
 
// Javascript program to check
// for a leap year
 
    function checkYear( year) {
        // If a year is multiple of 400,
        // then it is a leap year
        if (year % 400 == 0)
            return true;
 
        // Else If a year is multiple of 100,
        // then it is not a leap year
        if (year % 100 == 0)
            return false;
 
        // Else If a year is multiple of 4,
        // then it is a leap year
        if (year % 4 == 0)
            return true;
        return false;
    }
 
    // Driver method
      
        let year = 2000;
        document.write(checkYear(2000) ? "Leap Year" : "Not a Leap Year");
 
 
// This code is contributed by shikhasingrajput
 
</script>
Comment

PREVIOUS NEXT
Code Example
Javascript :: form submit with ajax 
Javascript :: hreroku 
Javascript :: javascript detect if active element is writable 
Javascript :: how ton give form widget to zoho creaor 
Javascript :: deletenode javascript 
Javascript :: create type in javascript 
Javascript :: how to get specific property name with numbers from object in javascript 
Javascript :: express roteamento 
Javascript :: creating a react app from scratch 
Javascript :: setCount 
Javascript :: $( ) jquery 
Javascript :: how to compile javascript class to function 
Javascript :: node js orderby method 
Javascript :: adonis model inheritance 
Javascript :: draw image inside canvas width 100% 
Javascript :: autonumeric stimulus 
Javascript :: Laravel Vue.js API: axios, FormData() is empty 
Javascript :: javascript Vue Component Loading Before Vuex Data Is Set 
Javascript :: Randomly getting error 500 in Azure App Service when downloading angularjs template 
Javascript :: angularjs How to get time difference from ZoneDateTime in javascript 
Javascript :: Get value from each *ngFor ionic 4, ionic 5, ionic 6 
Javascript :: Why is <CalendarStrip / not working properly 
Javascript :: How to use search/filter for HTML Divs generated from JSON data using JavaScript 
Javascript :: assignment is to create a small website using NestJS in the backend and basic HTML CSS in the frontend 
Javascript :: upload node js 
Javascript :: store api key in environment variable ngular 
Javascript :: chat v2 msg and time good 
Javascript :: Class Which Can Create An Instance Of The Same Type 
Javascript :: chrome page transitions 
Javascript :: empty or remove div span class 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =