-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
70 lines (63 loc) · 2.73 KB
/
script.js
File metadata and controls
70 lines (63 loc) · 2.73 KB
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
jQuery(document).ready(function(){
function runOperation(){
$(".byte1 .circle").each(function(){
$(".byte2").removeClass("inactive");
var bitIndex = $(this).attr("bit");
var bitValue1 = $(this).attr("bit-value");
var bitValue2 = $(".byte2 .circle:nth-child(" + (Number(bitIndex)+1).toString() + ")").attr("bit-value");
//AND Operator
if($(".operations .operation.and").hasClass("selected")){
if(bitValue1 == "true" && bitValue2 == "true" ){
$(".result .circle:nth-child(" + (Number(bitIndex)+1).toString() + ")").css({"background-color":"white"});
}else{
$(".result .circle:nth-child(" + (Number(bitIndex)+1).toString() + ")").css({"background-color":"transparent"});
}
}
//OR
else if($(".operations .operation.or").hasClass("selected")){
if(bitValue1 == "true" || bitValue2 == "true" ){
$(".result .circle:nth-child(" + (Number(bitIndex)+1).toString() + ")").css({"background-color":"white"});
}else{
$(".result .circle:nth-child(" + (Number(bitIndex)+1).toString() + ")").css({"background-color":"transparent"});
}
}
//XOR
else if($(".operations .operation.xor").hasClass("selected")){
if(bitValue1 != bitValue2 ){
$(".result .circle:nth-child(" + (Number(bitIndex)+1).toString() + ")").css({"background-color":"white"});
}else{
$(".result .circle:nth-child(" + (Number(bitIndex)+1).toString() + ")").css({"background-color":"transparent"});
}
}
//NOT
else if($(".operations .operation.not").hasClass("selected")){
$(".byte2").addClass("inactive");
if(bitValue1 != "true"){
$(".result .circle:nth-child(" + (Number(bitIndex)+1).toString() + ")").css({"background-color":"white"});
}else{
$(".result .circle:nth-child(" + (Number(bitIndex)+1).toString() + ")").css({"background-color":"transparent"});
}
}
//Update explaination
$(".explanation").html($(".operations .operation.selected").attr("explain-text"));
});
}
$(".circle").on("click",function(){
if($(this).hasClass("active")){
$(this).removeClass("active");
$(this).attr({"bit-value":"false"});
}else{
$(this).addClass("active");
$(this).attr({"bit-value":"true"})
}
runOperation();
});
$(".operation").on("click",function(){
$(".operation").each(function(){
$(this).removeClass("selected");
});
$(this).addClass("selected");
runOperation();
});
runOperation();
});