-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex10.html
More file actions
47 lines (42 loc) · 1.07 KB
/
Copy pathex10.html
File metadata and controls
47 lines (42 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<DOCTYPE! html>
<html>
<head>
<meta charset="UTF-8" ; />
<title>Exercise 10</title>
</head>
<body>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
var year = Number(prompt("enter a year"));
var counter = 20;
function leapyear(years, num) {
years = parseInt(years);
var origNum = num;
years++;
var leapYears = "";
while (num > 0) {
if (
years % 4 === 0 &&
(years % 100 !== 0 || (years % 100 === 0 && years % 400 === 0))
) {
if (num === 1) {
leapYears += years + ".";
} else {
leapYears += years + ", ";
}
years++;
num--;
} else {
years++;
}
}
return "The next " + origNum + " leap years are " + leapYears;
}
document.write(leapyear(year, counter));
}
</script>
</body>
</html>
</DOCTYPE!>