-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
30 lines (29 loc) · 1019 Bytes
/
index.html
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
<html>
<head>
<title>JavaScript to print Even Numbers within a Range!</title>
<script>
function printOdds(){
//get the start and end range from user
var start = parseInt(document.getElementById("start").value);
var end = parseInt(document.getElementById("end").value);
var oddNums = "<br>Even Numbers:<br>";
for(i=start; i<=end; i++){
// let's divide the value by 2
// if the reminder is zero then it's an Even number
if(i % 3 == 0){
oddNums += i + "<br>";
}
}
//print the values
document.getElementById("result").innerHTML = oddNums;
}
</script>
</head>
<body>
<h3>JavaScript to print Even Numbers within a Range!</h3>
Start: <input type="number" min="0" id="start" value="1" />
End: <input type="number" id="end" min="1" value="30" />
<input type="button" onclick="printOdds()" value="Print Even Numbers" />
<div id="result"></div>
</body>
</html>