xxxxxxxxxx
//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 );
xxxxxxxxxx
function isLeap(year) {
return (year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0)) ? "Leap year." : "Not leap year.";
}
xxxxxxxxxx
function isLeapYear(year) {
if ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0) {
return true;
} else {
return false;
}
}
console.log(isLeapYear(2000));
xxxxxxxxxx
function isLeapYear(year) {
// Check if the year is divisible by 4
if (year % 4 === 0) {
// If the year is divisible by 100, it must also be divisible by 400 to be a leap year
if (year % 100 === 0 && year % 400 !== 0) {
return false;
}
return true;
}
return false;
}
// Example usage
console.log(isLeapYear(2020)); // Output: true
console.log(isLeapYear(1900)); // Output: false
console.log(isLeapYear(2000)); // Output: true
console.log(isLeapYear(2022)); // Output: false
xxxxxxxxxx
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
xxxxxxxxxx
var leapYear = prompt('Please enter year to check if it is a leap year :');
if ((leapYear % 4 === 0 && leapYear % 100 !== 0) || leapYear % 400 === 0) {
alert(`${leapYear} : is a leap year`);
} else {
alert(`${leapYear} : is not a leap year`);
}
xxxxxxxxxx
var leapYear = prompt('Please enter year to check if it is a leap year :');
if ((leapYear % 4 === 0 && leapYear % 100 !== 0) || leapYear % 400 === 0) {
alert(`${leapYear} : is a leap leap year`);
} else {
alert(`${leapYear} : is not a leap leap year`);
}
xxxxxxxxxx
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) {
document.write(year + ' is a leap year');
}
xxxxxxxxxx
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) {
document.write(year + ' is a leap year');
}
xxxxxxxxxx
if ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0)) {
document.write(year + ' is a leap year');
}