add first functionality

This commit is contained in:
Florian Schmid 2023-04-12 01:25:57 +02:00
parent 3e5596ed9e
commit 70ae50457f

33
game.js
View File

@ -7,8 +7,7 @@ async function main() {
.then((response) => response.json()) .then((response) => response.json())
.then((json) => cpuList = json); .then((json) => cpuList = json);
currentCpu = getRandomCpu(); updateLayout();
nextCpu = getRandomCpu();
} }
function getRandomCpu() { function getRandomCpu() {
@ -19,6 +18,36 @@ function getRandomCpu() {
} }
} }
function btnLowerClick() {
if (currentCpu.score < nextCpu.score) {
showResult(true);
return;
}
showResult(false);
}
function btnHigherClick() {
}
function showResult(isCorrect) {
if (isCorrect) {
document.getElementById("col2").style.backgroundColor = "lightgreen";
}
else {
document.getElementById("col2").style.backgroundColor = "#FF4444";
}
}
function updateLayout() {
currentCpu = getRandomCpu();
document.getElementById("currentCpuTitle").innerText = currentCpu.name;
// add "." to large numbers
document.getElementById("currentCpuScore").innerText = currentCpu.score.toString().length > 3 ? currentCpu.score.toString().slice(0, currentCpu.score.toString().length - 3) + "." + currentCpu.score.toString().slice(currentCpu.score.toString().length - 3) : currentCpu.score;
nextCpu = getRandomCpu();
document.getElementById("nextCpuTitle").innerText = nextCpu.name;
}
function getRandomInt(min, max) { function getRandomInt(min, max) {
min = Math.ceil(min); min = Math.ceil(min);
max = Math.floor(max); max = Math.floor(max);