From 8833deaace45296af4821dd2bd3aa608c127e9f0 Mon Sep 17 00:00:00 2001 From: Florian Schmid Date: Fri, 14 Apr 2023 00:02:35 +0200 Subject: [PATCH] bug fix + add multiple correct anwsers --- gst.js | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/gst.js b/gst.js index 3b23197..7029e2e 100644 --- a/gst.js +++ b/gst.js @@ -25,7 +25,7 @@ function getRandomCpu() { let randomIndex; do { randomIndex = getRandomInt(0, cpuList.length) - } while (typeof(cpuList[randomIndex]["type"]) == null) + } while (typeof(cpuList[randomIndex]["type"]) == null || cpuList[randomIndex]["type"] == "null" || cpuList[randomIndex]["type"] == null); return { @@ -51,6 +51,10 @@ export async function btnClick(typ) { let btns = [btnDesktop, btnLaptop, btnMobile, btnServer]; + btns.forEach((el) => { + el.setAttribute("disabled", ""); + }) + switch (typ) { case 0: btnDesktop.style.backgroundColor = "#FF4444"; @@ -66,25 +70,24 @@ export async function btnClick(typ) { break; } - switch (currentCpu.type) { - case "Desktop": - btnDesktop.style.backgroundColor = "lightgreen"; - break; - case "Laptop": - btnLaptop.style.backgroundColor = "lightgreen"; - break; - case "Mobile/Embedded": - btnMobile.style.backgroundColor = "lightgreen"; - break; - case "Server": - btnServer.style.backgroundColor = "lightgreen"; - break; + if(currentCpu.type.includes("Desktop")) { + btnDesktop.style.backgroundColor = "lightgreen"; + } + if(currentCpu.type.includes("Laptop")) { + btnLaptop.style.backgroundColor = "lightgreen"; + } + if(currentCpu.type.includes("Mobile/Embedded")) { + btnMobile.style.backgroundColor = "lightgreen"; + } + if(currentCpu.type.includes("Server")) { + btnServer.style.backgroundColor = "lightgreen"; } await delay(2000); btns.forEach( (el) => { el.style.backgroundColor = "#3CC3FA"; + el.removeAttribute("disabled"); }) nextRound();