add highScore

This commit is contained in:
Florian Schmid 2023-04-12 14:42:03 +02:00
parent 2145b93704
commit 9c19249b72
2 changed files with 11 additions and 0 deletions

View File

@ -63,6 +63,11 @@
</div> </div>
</div> </div>
<div class="h3 text-center">
High Score:
<strong><span id="highScore" style="color: crimson;">0</span></strong>
</div>
<!-- <div class="footer"> <!-- <div class="footer">
<a href="https://www.flaticon.com/free-icons/processor" title="processor icons">Processor icons created by kerismaker - Flaticon</a> <a href="https://www.flaticon.com/free-icons/processor" title="processor icons">Processor icons created by kerismaker - Flaticon</a>
</div> --> </div> -->

View File

@ -6,6 +6,7 @@ var nextCpu;
// current user score // current user score
var score; var score;
var highScore;
export async function main() { export async function main() {
await (fetch('./data.json') await (fetch('./data.json')
@ -15,6 +16,7 @@ export async function main() {
currentCpu = getRandomCpu(); currentCpu = getRandomCpu();
nextCpu = getRandomCpu(); nextCpu = getRandomCpu();
score = 0; score = 0;
highScore = 0;
updateLayout(); updateLayout();
} }
@ -40,6 +42,10 @@ function showResult(isCorrect) {
document.getElementById("col2").style.backgroundColor = isCorrect ? "lightgreen" : "#FF4444"; document.getElementById("col2").style.backgroundColor = isCorrect ? "lightgreen" : "#FF4444";
score = isCorrect ? score + 1 : 0; score = isCorrect ? score + 1 : 0;
if (score > highScore) {
highScore = score;
document.getElementById("highScore").innerText = highScore;
}
document.getElementById("score").innerText = score; document.getElementById("score").innerText = score;
countUp(); countUp();