-
Notifications
You must be signed in to change notification settings - Fork 0
/
onto.html
110 lines (91 loc) · 3.58 KB
/
onto.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="styles.css">
<link rel="icon" href="images/icon.ico">
<title>onto</title>
</head>
<body>
<div class="graphic">
<svg id="ontoGraphic" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 80 40">
<circle id="1" cx="10" cy="10" r="5" fill="black"/>
<circle id="2" cx="26" cy="20" r="5" fill="black" />
<circle id="3" cx="20" cy="30" r="5" fill="black" />
<circle id="4" cx="40" cy="10" r="5" fill="black" />
<circle id="5" cx="50" cy="16" r="5" fill="black" />
<circle id="6" cx="38" cy="28" r="5" fill="black" />
<circle id="7" cx="7" cy="20" r="5" fill="black" />
</svg>
</div>
<div class="pageButton">
<h1 id="resetButton" onclick="reset()" style="display: none">reset</h1>
<h1 id="jumpButton" onclick="jumpFnc()">jump</h1>
</div>
<div class="backButton"><a href="index.html">back</a></div>
<script>
const numCircles = 7;
var trueOne, trueTwo, trueThree, trueFour, trueFive, trueSix, trueSeven;
var allTrue = false;
// TODO: randomly place 7 circles that don't overlap
function jumpFnc() {
// randomly choose a circle to jump to
var num = Math.floor(Math.random() * numCircles) + 1;
var index = num.toString();
// once a circle has been jumped to, make the corresponding variable true
if (num == 1) {
trueOne = true;
} else if (num == 2) {
trueTwo = true;
} else if (num == 3) {
trueThree = true;
} else if (num == 4) {
trueFour = true;
} else if (num == 5) {
trueFive = true;
} else if (num == 6) {
trueSix = true;
} else if (num == 7) {
trueSeven = true;
};
allTrue = (trueOne && trueTwo && trueThree && trueFour && trueFive && trueSix && trueSeven);
// update color of jumped-to circle
var currentColor = document.getElementById(index).getAttribute("fill");
var newColor;
if (currentColor == "black") {
newColor = "green";
} else if (currentColor == "green") {
newColor = "tomato";
} else if (currentColor == "tomato") {
newColor = "lightblue";
} else if (currentColor == "lightblue") {
newColor = "gold"
} else if (currentColor == "gold") {
newColor = "lightpink"
} else {
newColor = "green"
}
document.getElementById(index).setAttribute("fill", newColor);
// if all circles have been hit, light up because you've got something onto
if (allTrue) {
console.log("yep!");
document.getElementById("ontoGraphic").style.background = "red";
// add a reset button
document.getElementById("resetButton").style.display = "block";
}
};
function reset() {
document.getElementById("1").setAttribute("fill", "black");
document.getElementById("2").setAttribute("fill", "black");
document.getElementById("3").setAttribute("fill", "black");
document.getElementById("4").setAttribute("fill", "black");
document.getElementById("5").setAttribute("fill", "black");
document.getElementById("6").setAttribute("fill", "black");
document.getElementById("7").setAttribute("fill", "black");
document.getElementById("ontoGraphic").style.background = "none";
document.getElementById("resetButton").style.display = "none";
}
</script>
</body>
</html>