summaryrefslogtreecommitdiff
path: root/rannak/mangud/partorg/sonaragastik/script.js
blob: 6151b9e7684b7c1f99366ef6b292aecfa5d5b858 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
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", "plaanimajandus",
                  "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];
            }

            console.log(hetkeKlass);
            document.querySelector(".V"+hetkeKlass).classList.add("done");
        
            if (!õiged.includes(hetkeKlass)) {
                õiged.push(hetkeKlass);
                õigedCounter++;
                console.log(õigedCounter);
            }
            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;
    localStorage.setItem('roll', "Partogi");
    btn.onclick = () => location.href = "../../../endPage";

    // submit btn
	const subButton = document.querySelector(".subBtn");
	subButton.disabled = true;

	counter = 0;
}