-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmapScript2.js
More file actions
153 lines (134 loc) · 3.61 KB
/
mapScript2.js
File metadata and controls
153 lines (134 loc) · 3.61 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
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
// Used to toggle the menu on small screens when clicking on the menu button
function myFunction() {
var x = document.getElementById("navDemo");
if (x.className.indexOf("w3-show") == -1) {
x.className += " w3-show";
} else {
x.className = x.className.replace(" w3-show", "");
}
}
let walkBadge = {
distance: 10,
unlocked: false,
};
let peopleBadge = {
people: 5,
unlocked: false,
};
let distWalked = 0;
let peopleMet = 0;
const distGoal = 10;
const peopleGoal = 5;
let peopleCheck = "";
let walkCheck = "";
// Retrieve data from database, repeat this function every 5 seconds
function walkFunction() {
console.log("walkFunction");
const distSaved = JSON.parse(localStorage.getItem("distWalked"));
if (distSaved) {
distWalked = distSaved;
}
let newWalk = 1;
localStorage.setItem("distWalked", JSON.stringify(distWalked + newWalk));
if (distWalked >= distGoal) {
walkCheck = ' checked="checked"';
clearInterval(walkInterval);
}
render();
}
function peopleFunction() {
console.log("peopleFunction");
const peopleSaved = JSON.parse(localStorage.getItem("peopleMet"));
if (peopleSaved) {
peopleMet = peopleSaved;
}
let newPeople = 1;
localStorage.setItem("peopleMet", JSON.stringify(peopleMet + newPeople));
if (peopleMet >= peopleGoal) {
peopleCheck = ' checked="checked"';
clearInterval(peopleInterval);
}
render();
}
function checktimepass() {
const today = new Date();
let h = today.getHours();
let m = today.getMinutes();
let s = today.getSeconds();
console.log(today.tostring());
if (h == 0 && m == 0 && s == 0) {
localStorage.clear();
distWalked = 0;
peopleMet = 0;
walkCheck = "";
peopleCheck = "";
walkInterval = setInterval(walkFunction, 1000);
peopleInterval = setInterval(peopleFunction, 1000);
render();
}
setTimeout(checktimepass, 1000);
}
let walkInterval = setInterval(walkFunction, 1000);
let peopleInterval = setInterval(peopleFunction, 1000);
let timeInterval = setInterval(checktimepass, 1000);
function render() {
console.log("render");
const ulEl = document.getElementById("ul-el");
ulEl.innerHTML = `
<li>
<p>
Distance walked: ${distWalked} / ${distGoal} km
<label class="container-checkbox">
<input type="checkbox" ${walkCheck}>
<span class="checkmark"></span>
</label>
</p>
</li>
<li>
<p>
People met: ${peopleMet} / ${peopleGoal} person(s)
<label class="container-checkbox">
<input type="checkbox" ${peopleCheck}>
<span class="checkmark"></span>
</label>
</p>
</li>
<li>
<p>
<img src="images/tourist.png" alt="walking icon"/> Visit the museum
<label class="container-checkbox">
<input type="checkbox">
<span class="checkmark"></span>
</label>
</p>
</li>
<li>
<p>
<img src="images/world.png" alt="walking icon"/> Explore the GameOn arcade
<label class="container-checkbox">
<input type="checkbox">
<span class="checkmark"></span>
</label>
</p>
</li>
<li>
<p>
<img src="images/meet.png" alt="walking icon"/> Meet and mingle in Chancery Square
<label class="container-checkbox">
<input type="checkbox">
<span class="checkmark"></span>
</label>
</p>
</li>`;
}
const clearBtn = document.getElementById("clear-btn");
clearBtn.addEventListener("click", function () {
localStorage.clear();
distWalked = 0;
peopleMet = 0;
walkCheck = "";
peopleCheck = "";
walkInterval = setInterval(walkFunction, 1000);
peopleInterval = setInterval(peopleFunction, 1000);
render();
});