-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscores.js
36 lines (31 loc) · 1.03 KB
/
scores.js
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
function init() {
var highScore = document.querySelector("#highScore");
var clear = document.querySelector("#clear");
var goBack = document.querySelector("#goBack");
// Event listener to clear scores
clear.addEventListener("click", function () {
localStorage.clear();
// reload the page the rerender the list
location.reload();
});
// Retreives local stroage
var allScores = localStorage.getItem("allScores");
allScores = JSON.parse(allScores);
if (allScores !== null) {
for (var i = 0; i < allScores.length; i++) {
var createLi = document.createElement("li");
createLi.textContent = allScores[i].initials + " " + allScores[i].score;
highScore.appendChild(createLi);
}
// allScores.forEach(user => {
// var createLi = document.createElement("li");
// createLi.textContent = user.initials + " " + user.score;
// highScore.appendChild(createLi);
// });
}
// Event listener to move to index page
goBack.addEventListener("click", function () {
window.location.replace("index.html");
});
}
init();