-
Notifications
You must be signed in to change notification settings - Fork 0
/
history.js
40 lines (31 loc) · 1.2 KB
/
history.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
37
38
39
40
const histories = document.getElementById("histories");
function addHistory(questionText, timeTaken, errorCount) {
const newRow = document.createElement("div");
newRow.classList.add("card");
newRow.innerHTML = `
<h3>${questionText}</h3>
<div>
<p>You took: <span class="bold">${timeTaken}</span> seconds</p>
<p>You made <span class="bold red">${errorCount}</span> mistakes</p>
</div>
`;
histories.appendChild(newRow);
let previousTests = JSON.parse(localStorage.getItem("testHistory")) || [];
previousTests.push({ questionText, timeTaken, errorCount });
localStorage.setItem("testHistory", JSON.stringify(previousTests));
displayHistory();
}
function displayHistory() {
histories.innerHTML = "";
const previousTests = JSON.parse(localStorage.getItem("testHistory")) || [];
previousTests.forEach((test) => {
const newRow = document.createElement("div");
newRow.classList.add("card");
newRow.innerHTML = `
<h3>${test.questionText}</h3>
<p>You took: <span class="bold">${test.timeTaken}</span> seconds</p>
<p>You made <span class="bold red">${test.errorCount}</span> mistakes</p>
`;
histories.appendChild(newRow);
});
}