-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharray.js
147 lines (121 loc) · 3.46 KB
/
array.js
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
139
140
141
142
143
144
let anton = {
'bro': 0,
'dude': 0
};
console.log(anton);
function checkBroDude() {
if (anton['bro'] == 1 && anton['dude'] == 1) {
document.getElementById("makkerCheck").innerHTML = "Anton er en brolicious dude";
} else {
document.getElementById("makkerCheck").innerHTML = "Anton er IKKE en brolicious dude";
};
}
const buttonBro = document.getElementById("buttonBro");
const buttonDude = document.getElementById("buttonDude");
function flipFlop(obj, key, btn) {
switch (obj[key]) {
case 0:
obj[key] = 1;
btn.style.backgroundColor = "green";
btn.style.color = "white";
checkBroDude();
break;
case 1:
obj[key] = 0;
btn.style.backgroundColor = "";
btn.style.color = "";
checkBroDude();
break;
default:
console.log("I don't know what to tell you. I guess you broke the code.");
break;
}
}
buttonBro.addEventListener("click", flipFlop.bind(null, anton, Object.keys(anton)[0], buttonBro));
buttonDude.addEventListener("click", flipFlop.bind(null, anton, Object.keys(anton)[1], buttonDude));
/* buttonBro.onclick = function() {
switch (anton.bro) {
case 1:
anton.bro = 0;
console.log(anton);
document.getElementById("buttonBro").style.backgroundColor = "";
document.getElementById("buttonBro").style.color = "";
checkBroDude();
break;
case 0:
anton.bro = 1;
console.log(anton);
document.getElementById("buttonBro").style.backgroundColor = "green";
document.getElementById("buttonBro").style.color = "white";
checkBroDude();
break;
default:
console.log("I don't know what to tell you. I guess you broke the code.");
break;
}
}; */
/* buttonBro.onclick = flipFlop(anton, anton.bro, buttonBro)
buttonDude.onclick = flipFlop(anton, anton.dude, buttonDude) */
/* buttonBro.addEventListener('click', function() {
changeBro(anton);
});
buttonDude.addEventListener('click', function() {
changeDude(anton);
});
function changeBro(obj) {
let objLen = Object.keys(obj).length;
console.log("Antal keys:" + objLen);
for (let i = 0; i < objLen; i++) {
console.log("bro" + obj['bro'] && checks < objLen);
if (obj['bro'] == 0) {
obj['bro'] = 1;
checks++;
} else if (obj['bro'] == 1) {
obj['bro'] = 0;
checks--;
}
}
if (checks == objLen) {
document.getElementById("makkerCheck").innerHTML = "Anton er en brolicious dude";
} else {
document.getElementById("makkerCheck").innerHTML = "Anton er IKKE en brolicious dude";
}
console.log(anton)
}
function changeDude(obj) {
let objLen = Object.keys(obj).length;
console.log("Antal keys:" + objLen);
for (let i = 0; i < objLen; i++) {
console.log("dude" + obj['dude'] && checks < objLen);
if (obj['dude'] == 0) {
obj['dude'] = 1;
checks++;
} else if (obj['dude'] == 1) {
obj['dude'] = 0;
checks--
}
}
if (checks == objLen) {
document.getElementById("makkerCheck").innerHTML = "Anton er en brolicious dude";
} else {
document.getElementById("makkerCheck").innerHTML = "Anton er IKKE en brolicious dude";
}
console.log(anton)
} */
/* alert(anton.bro); */
/* function sayHi() {
console.log("Hi");
console.log("Bye");
}
function sum(a, b) {
const sum = a + b;
return a + b;
}
const value = sum(1, 2);
console.log(value);
sayHi();
if (Array.isArray(anton)) {
console.log("bro is an array");
} else {
console.log("bro is not an array");
}; */