fix naming

This commit is contained in:
Florian Schmid 2023-04-12 20:12:22 +02:00
parent fc76ba9ecf
commit 53827029a4
2 changed files with 11 additions and 10 deletions

View File

@ -41,7 +41,7 @@
<div class="row"> <div class="row">
<div class="col-12 text-center"> <div class="col-12 text-center">
<div class="h2">Current Score: <span id="score" style="color: violet;">0</span></div> <div class="h2">Current Score: <span id="score" style="color: violet;">0</span></div>
<div class="h4">Personal Highscore: <span id="highscore" style="color: violet;">0</span></div> <div class="h4">Personal Highscore: <span id="highScore" style="color: crimson;">0</span></div>
</div> </div>
</div> </div>
<div class="row mt-3"> <div class="row mt-3">

19
game.js
View File

@ -6,13 +6,13 @@ var nextCpu;
// current user score // current user score
var score; var score;
var highscore; var highScore;
function setHighscore(score) { function setHighScore(score) {
const currHighscore = localStorage.getItem("highscore_cpu") const currHighScore = localStorage.getItem("highScore_cpu")
if (currHighscore < score) { if (currHighScore < score) {
localStorage.setItem("highscore_cpu", score) localStorage.setItem("highScore_cpu", score)
highscore = score highScore = score
} }
} }
@ -24,7 +24,7 @@ export async function main() {
currentCpu = getRandomCpu(); currentCpu = getRandomCpu();
nextCpu = getRandomCpu(); nextCpu = getRandomCpu();
score = 0; score = 0;
highscore = localStorage.getItem("highscore_cpu") ?? 0 highScore = localStorage.getItem("highScore_cpu") ?? 0
updateLayout(); updateLayout();
} }
@ -50,7 +50,7 @@ function showResult(isCorrect) {
document.getElementById("col2").style.backgroundColor = isCorrect ? "lightgreen" : "#FF4444"; document.getElementById("col2").style.backgroundColor = isCorrect ? "lightgreen" : "#FF4444";
if (!isCorrect) { if (!isCorrect) {
setHighscore(score) setHighScore(score)
} }
score = isCorrect ? score + 1 : 0; score = isCorrect ? score + 1 : 0;
if (score > highScore) { if (score > highScore) {
@ -64,7 +64,8 @@ function showResult(isCorrect) {
// updates view based on the cpu objects // updates view based on the cpu objects
function updateLayout() { function updateLayout() {
document.getElementById("highscore").innerText = highscore; document.getElementById("highScore").innerText = highScore;
document.getElementById("currentCpuTitle").innerText = currentCpu.name; document.getElementById("currentCpuTitle").innerText = currentCpu.name;
// add "." to large numbers // add "." to large numbers
document.getElementById("currentCpuScore").innerText = new Intl.NumberFormat().format(currentCpu.score) document.getElementById("currentCpuScore").innerText = new Intl.NumberFormat().format(currentCpu.score)