JavaScript judging leap years

Claim:

Enter a year to determine whether it is a leap year (leap year: a year that is divisible by 4 and not divisible by 100 or divisible by 400)
Insert picture description here
Insert picture description here

Code:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        // 利用函数判断闰年
        function isRunYear(year) {
     
     
            // 是闰年返回true,否则返回false 
            var flag = false;
            if (year % 4 == 0 && year % 100 != 0 || year % 400 == 0) {
     
     
                flag = true;
            }
            return flag;
        }
        var year = Number(prompt('请输入年份:'));
        alert(isRunYear(year));
    </script>
</body>

</html>

Guess you like

Origin blog.csdn.net/Jack_lzx/article/details/109241701