JavaScript tahun lompatan
function isLeapYear(year){
if(year % 400 === 0 && year % 4 === 0){
return true
} else {
return false
}
}
Glamorous Goose
function isLeapYear(year){
if(year % 400 === 0 && year % 4 === 0){
return true
} else {
return false
}
}
function isLeapYear(year) {
if (year % 400 === 0) return true;
if (year % 100 === 0) return false;
return year % 4 === 0;
}
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
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`);
}
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`);
}