diff options
author | Rasmus Luha <rasmus.luha@gmail.com> | 2022-10-31 00:08:28 +0200 |
---|---|---|
committer | Rasmus Luha <rasmus.luha@gmail.com> | 2022-10-31 00:08:28 +0200 |
commit | 4125072dbedaa6dc4f185e801bc8f30c12237125 (patch) | |
tree | 1d4d3d2f6441122ad93da7c25d2768f05f1aaa29 /rannak/mangud/partorg/sonaragastik/script.js | |
parent | 91b1b6d3305606717e3cdf0c4756571a5a84f95c (diff) |
sõnarägastik done + add to index
Diffstat (limited to 'rannak/mangud/partorg/sonaragastik/script.js')
-rw-r--r-- | rannak/mangud/partorg/sonaragastik/script.js | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/rannak/mangud/partorg/sonaragastik/script.js b/rannak/mangud/partorg/sonaragastik/script.js new file mode 100644 index 0000000..ab5ebe4 --- /dev/null +++ b/rannak/mangud/partorg/sonaragastik/script.js @@ -0,0 +1,104 @@ +function randomLetters(){ + for (let node of document.querySelectorAll("td")) { + if (node.textContent != "") continue; + let charcode = Math.round(65 + Math.random() * 25) + node.textContent = String.fromCharCode(charcode) + } +} +randomLetters(); + +function clickEventAdder(){ + for (let node of document.querySelectorAll("td")) { + node.addEventListener("click", () => { + if (!node.classList.contains("selected")){ + node.classList.add("selected"); + } + else{ + node.classList.remove("selected"); + } + + }); + } +} +clickEventAdder(); + + + +function message(msg, color){ + messageBox = document.querySelector(".messageBox"); + messageBox.innerHTML = msg; + messageBox.style.color = color; +} + + + +// Main stuff + +const vastused = ["valuuta", "tuusik", "tsaika", "redis", "plaanimajadnus", + "rubla", "letialuneKaup", "talongid", "maantee", + "piiritsoon", "defitsiit"] +let õiged = new Array(); +let õigedCounter = 0; + +function proovi(){ + for (let klass of vastused){ + + const ruudud = document.querySelectorAll("."+klass); + const allSelected = document.querySelectorAll(".selected").length; + let kokku = ruudud.length; + let counter = 0; + + + for (let ruut of ruudud){ + if (ruut.classList.contains("selected")) + counter++; + } + + if (counter == kokku && counter == allSelected){ + const selectd = document.querySelectorAll(".selected"); + let hetkeKlass; + + for (let ruut of ruudud){ + ruut.classList.remove("selected"); + ruut.classList.add("done"); + if (ruut.classList.length == 2) + hetkeKlass = ruut.classList[0]; + } + + document.querySelector(".V"+hetkeKlass).classList.add("done"); + + if (!õiged.includes(hetkeKlass)) { + õiged.push(hetkeKlass); + õigedCounter++; + console.log("DicoDisco GoodGood") + } + if (õigedCounter >= 11) + moveOnEnable(); + + + message("Õige", "green"); + return; + } + + } //Outerloop + const selectd = document.querySelectorAll(".selected"); + for (let sel of selectd) + sel.classList.remove("selected"); + message("Proovi uuesti", "red"); +} + + + +// Button func +function moveOnEnable(){ + const btn = document.querySelector(".moveOn"); + btn.disabled = false; + btn.onclick = () => location.href = ""; + + // submit btn + const subButton = document.querySelector(".subBtn"); + subButton.disabled = true; + + counter = 0; +} + |