-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
175 lines (144 loc) · 6.54 KB
/
background.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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
document.getElementById("first-check").addEventListener("click", function () {
var user_input = document.getElementById("first-input").value;
var output = document.getElementById("first-output");
if (user_input == "3") {
output.innerHTML = "Correct! Well done.";
} else if (user_input == "4") {
output.innerHTML = "Close! Remember that computer scientists number the places start from 0, not 1";
} else if (user_input == "0") {
output.innerHTML = "Not quite! Remember that we number the places from right to left, instead of left to right";
} else {
output.innerHTML = "Incorrect. Try again!";
}
});
document.getElementById("first-input").addEventListener("keyup", function(event) {
if (event.code === "Enter") {
document.getElementById("first-check").click();
}
});
// -------------------------------------
document.getElementById("second-check").addEventListener("click", function () {
var user_input = document.getElementById("second-input").value;
var output = document.getElementById("second-output");
if (user_input == "2") {
output.innerHTML = "Correct! Well done.";
} else if (user_input == "3") {
output.innerHTML = "Close! Remember that computer scientists number the places start from 0, not 1";
} else if (user_input == "1") {
output.innerHTML = "Not quite! Remember that we number the places from right to left, instead of left to right";
} else {
output.innerHTML = "Incorrect. Try again!";
}
});
document.getElementById("second-input").addEventListener("keyup", function(event) {
if (event.code === "Enter") {
document.getElementById("second-check").click();
}
});
// -------------------------------------
document.getElementById("third-check").addEventListener("click", function () {
var user_input = document.getElementById("third-input").value;
var output = document.getElementById("third-output");
if (user_input == "1") {
output.innerHTML = "Correct! Well done.";
} else if (user_input == "2") {
output.innerHTML = "Close! Remember that computer scientists number the places start from 0, not 1";
} else {
output.innerHTML = "Incorrect. Try again!";
}
});
document.getElementById("third-input").addEventListener("keyup", function(event) {
if (event.code === "Enter") {
document.getElementById("third-check").click();
}
});
// -------------------------------------
document.getElementById("fourth-check").addEventListener("click", function () {
var user_input = document.getElementById("fourth-input").value;
var output = document.getElementById("fourth-output");
if (user_input == "0") {
output.innerHTML = "Correct! Well done.";
} else if (user_input == "1") {
output.innerHTML = "Close! Remember that computer scientists number the places start from 0, not 1";
} else if (user_input == "3") {
output.innerHTML = "Not quite! Remember that we number the places from right to left, instead of left to right";
} else {
output.innerHTML = "Incorrect. Try again!";
}
});
document.getElementById("fourth-input").addEventListener("keyup", function(event) {
if (event.code === "Enter") {
document.getElementById("fourth-check").click();
}
});
// -------------------------------------
document.getElementById("btd-check").addEventListener("click", function() {
var user_input = document.getElementById("btd-input").value;
var output = document.getElementById("btd-output");
if (user_input == "146") {
output.innerHTML = "Correct! Well done.";
} else {
output.innerHTML = "Incorrect. The number you inputted is equivalent to " + parseInt(user_input).toString(2) + ". Try again!";
}
});
document.getElementById("btd-input").addEventListener("keyup", function(event) {
if (event.code === "Enter") {
document.getElementById("btd-check").click();
}
});
// -------------------------------------
document.getElementById("dtb-check").addEventListener("click", function() {
var user_input = document.getElementById("dtb-input").value;
var output = document.getElementById("dtb-output");
if (user_input == "1110") {
output.innerHTML = "Correct! Well done.";
} else {
output.innerHTML = "Incorrect. The number you inputted is equivalent to " + parseInt(user_input, 2).toString() + ". Try again!";
}
});
document.getElementById("dtb-input").addEventListener("keyup", function(event) {
if (event.code === "Enter") {
document.getElementById("dtb-check").click();
}
});
// -------------------------------------
document.getElementById("atn-check").addEventListener("click", function() {
var user_input = parseInt(document.getElementById("atn-input").value);
var output = document.getElementById("atn-output");
if (user_input == 43) {
output.innerHTML = "Correct! Well done.";
} else if (user_input < 0 || user_input > 127) {
output.innerHTML = "Be careful! The number you inputted won't convert to a valid ASCII character.";
} else if (user_input > 31) {
output.innerHTML = "Incorrect. The number you inputted is the ASCII character " + String.fromCharCode(user_input) + ".";
} else {
output.innerHTML = "Incorrect. The number you inputted can't be outputted.";
}
});
document.getElementById("atn-input").addEventListener("keyup", function(event) {
if (event.code === "Enter") {
document.getElementById("atn-check").click();
}
});
// -------------------------------------
document.getElementById("nta-check").addEventListener("click", function() {
var user_input = document.getElementById("nta-input").value;
var output = document.getElementById("nta-output");
var int_ver = user_input.charCodeAt(0);
if (user_input == "C") {
output.innerHTML = "Correct! Well done.";
} else if (user_input == "c") {
output.innerHTML = "Close! Remember that ASCII is case-sensitive";
} else if (user_input.length > 1 || user_input.length) {
output.innerHTML = "Be careful! You inputted more than one letter.";
} else if (int_ver < 0 || int_ver > 127) {
output.innerHTML = "Be careful! The character you inputted doesn't seem to be an ASCII character.";
} else {
output.innerHTML = "Incorrect. The ASCII character you inputted is " + int_ver.toString();
}
});
document.getElementById("nta-input").addEventListener("keyup", function(event) {
if (event.code === "Enter") {
document.getElementById("nta-check").click();
}
});