-
Notifications
You must be signed in to change notification settings - Fork 0
/
score.js
28 lines (23 loc) · 842 Bytes
/
score.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
// Declared variables
var highScore = document.querySelector("#highScore");
var clear = document.querySelector("#clear");
var goBack = document.querySelector("#back");
// On click to clear scores
clear.addEventListener("click", function () {
localStorage.clear();
location.reload();
});
// Get data from local storage and turns it into an object
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);
}
}
// Go back button
back.addEventListener("click", function () {
window.location.replace("./index.html");
});