-
Notifications
You must be signed in to change notification settings - Fork 0
/
scaleeditor.js
44 lines (39 loc) · 1.16 KB
/
scaleeditor.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
var pos1;
var pos2;
var pos3;
var pos4;
var pos5;
var pos6;
window.onload = function () {
var leds = document.getElementsByClassName("led");
var i;
for (i = 0; i < leds.length; i++) {
leds[i].classList.add("off");
leds[i].addEventListener("click", toggleLed);
}
pos1 = document.getElementsByClassName("pos1");
pos2 = document.getElementsByClassName("pos2");
pos3 = document.getElementsByClassName("pos3");
pos4 = document.getElementsByClassName("pos4");
pos5 = document.getElementsByClassName("pos5");
pos6 = document.getElementsByClassName("pos6");
calculateResult();
}
function calculateResult(){
var result = [calculatePosValue(pos1),calculatePosValue(pos2),calculatePosValue(pos3),calculatePosValue(pos4),calculatePosValue(pos5),calculatePosValue(pos6)];
document.getElementsByClassName("resultPosValues")[0].innerHTML = result;
}
function toggleLed(led){
led.target.classList.toggle("off");
led.target.classList.toggle("on");
calculateResult();
}
function calculatePosValue(positions){
var posValue = 0
for (i = 0; i < positions.length; i++) {
if (positions[i].classList.contains("on")){
posValue = posValue + Math.pow(2,i);
}
}
return posValue;
}