-
Notifications
You must be signed in to change notification settings - Fork 24
/
group_loop.html
57 lines (54 loc) · 1.34 KB
/
group_loop.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<!doctype html>
<html>
<head>
<title>Group Loop</title>
<script>
function checkNumbers(){
var someNumbers = [25, 11, -2, 14, "what?? This isn't a number!", -1, -10]
for(var i = 0; i < 7; i++){
var numberAsText = someNumbers[i]
var aNumber = parseInt(numberAsText)
if(numberAsText != "" && !isNaN(aNumber)){
var remainder = Math.abs(aNumber % 2)
if(aNumber != 0 && remainder == 0){
document.getElementById("result_display").innerHTML += "<p>"+
aNumber + " is even.</p>"
}
else if(aNumber != 0 && remainder == 1){
document.getElementById("result_display").innerHTML += "<p>"+
aNumber + " is odd.</p>"
}
else{
document.getElementById("result_display").innerHTML += "<p>"+
"0 is neither even nor odd.</p>"
}
}
else{
document.getElementById("result_display").innerHTML += "<p>Oops. Found something that wasn't a number in position " + i + ".</p>"
}
}
}
</script>
<style>
body{
background-color: LightGrey;
}
input{
border:none;
border-radius:5px;
box-shadow:0px 0px 5px #666666 inset;
height:25px;
width:200px;
text-indent:5px;
}
input:focus {
outline:none;
}
</style>
</head>
<body>
<h1>Even or Odd???</h1>
<button onclick="checkNumbers()">Check It!</button>
<section id="result_display"></section>
</body>
</html>