Home  >  Article  >  Web Front-end  >  What is the method to determine leap year in javascript?

What is the method to determine leap year in javascript?

王林
王林Original
2021-11-03 17:01:557908browse

How to determine leap year in javascript: [var year=Number(prompt("Please enter a year")); var isRun=year@0==0&&year 0!=0||year@0= =0; console.lo...].

What is the method to determine leap year in javascript?

#The operating environment of this article: windows10 system, javascript 1.8.5, thinkpad t480 computer.

Determining leap years in ordinary years is a problem often encountered in the process of learning programming. Everyone has encountered this problem when they were in school. I believe everyone has a way to solve this problem.

So if you are asked to use javascript language, how to solve this problem?

Specific code:

<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>判断闰年</title>
</head>
<body>
<script>
    //判断润年:
//(year%4==0&&year%100 != 0) ||(year%400==0);
    var year=Number(prompt("请输入一个年份"));
    var isRun=year%400==0&&year%100!=0||year%400==0;
    console.log(year+"是如年吗?"+isRun);

/*1.能被4整除,但不能被100整除
或
1.1年份能被4整除
同时满足
1.2不能被100整除
2.能被400整除
*
* 1.var year=2016;
* 1.1能不能被4整除
* year%4==0;
* 结果为真:则能被4整除
* 结果为假:则不能被4整除
*
* 1.2不能被100整除
* 结果为真:则不能被100整除
* 结果为假:则能被100整除
*
* 1.3能被400整除
* year%400==0
* 结果为真:则能被400整出
* 结果为假:则不能被400整除
* */

</script>
</body>
</html>

Recommended learning: javascript video tutorial

The above is the detailed content of What is the method to determine leap year in javascript?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn