From 9d10fe5a795de2759fe5f31029840563e0c7d161 Mon Sep 17 00:00:00 2001 From: ElGurkus Date: Mon, 2 Nov 2020 12:53:00 +0100 Subject: [PATCH] changed code -> You can no longer select another field if any field is selected --- code.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/code.js b/code.js index 0aed2aa..831fe13 100644 --- a/code.js +++ b/code.js @@ -3,13 +3,21 @@ for(let i = 0; i < 64; i++){ fieldId = i.toString(); document.getElementById("field"+fieldId).selected = 0; } +let somethingIsSelected = false; function selectField(field){ console.log(field.id); - if(field.selected === 0) { + for(let i = 0; i < 64; i++){ + fieldId = i.toString(); + if(document.getElementById("field"+fieldId).selected === 1){ + somethingIsSelected = true; + } + } + if(!somethingIsSelected) { field.style.backgroundColor = "rgb(227,8,8, 0.3)"; field.selected = 1; } else if (field.selected === 1){ field.style.backgroundColor = "rgb(255,255,255, 1)"; field.selected = 0; + somethingIsSelected = false; } } \ No newline at end of file