【JavaScript练习】函数封装判断闰年
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script>
// 函数封装判断闰年
// 闰年:能被4整除并且不能被100整除,或者被400整除
function isLeapYear(year) {
if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
return true;
} else {
return false;
}
}
console.log(isLeapYear(2000));
console.log(isLeapYear(2001));
</script>
</head>
<body>
</body>
</html>
运行结果