summaryrefslogtreecommitdiff
path: root/rannak/mangud/partorg/sonaragastik/script.js
blob: e137e37b2dcefbb555fcf423e97faacdd9f6b68a (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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
document.addEventListener('DOMContentLoaded', () => {
    let btn = document.querySelector('.modalButton');
    btn.click();
});


// Vars
curZindex = 1;



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", "tsaika", "redis", "plaanimajandus",
                  "rubla", "letialuneKaup", "talongid", "maantee",
                  "piiritsoon", "defitsiit"];

const horisontaalis = ["letialuneKaup", "talongid", "maantee",
                     "piiritsoon", "defitsiit" ];

let õiged = new Array();
let õigedCounter = 0;

function proovi(){

    let dones = new Array();

    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");

                dones.push(ruut);

                if (ruut.classList.length == 1)
                    hetkeKlass = ruut.classList[0];
            }

            //console.log("hetkeKlass: ",hetkeKlass);

            for (let el of dones){
                if (horisontaalis.includes(hetkeKlass)){
                    el.classList.add("doneH");
                }
                else{
                    el.classList.add("doneV");
                }
            }

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

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

	counter = 0;
}