-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHighscore.js
More file actions
24 lines (22 loc) · 768 Bytes
/
Highscore.js
File metadata and controls
24 lines (22 loc) · 768 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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();
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);
}
}
// Event listener to move to index page
goBack.addEventListener("click", function () {
window.location.replace("./index.html");
});