-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
40 lines (33 loc) · 989 Bytes
/
index.js
File metadata and controls
40 lines (33 loc) · 989 Bytes
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
let output = document.getElementById("outputArea");
const submitForm = () => {
let binaryToEnglishButton = document.getElementById("btnradio1").checked;
let englishToBinaryButton = document.getElementById("btnradio2").checked;
output.innerHTML = "";
let input = document.getElementById("input").value;
if (input === "") {
output.innerHTML = "Please enter a value...";
} else {
if (binaryToEnglishButton == true) {
binaryToEnglish(input);
}
if (englishToBinaryButton == true) {
englishToBinary(input);
}
}
resetForm();
};
const resetForm = () => {
let form = document.getElementById("form");
form.reset();
};
const binaryToEnglish = (input) => {
input = input.split(" ");
output.innerHTML = input
.map((elem) => String.fromCharCode(parseInt(elem, 2)))
.join("");
};
const englishToBinary = (input) => {
for (let i = 0; i < input.length; i++) {
output.innerHTML += input[i].charCodeAt(0).toString(2) + " ";
}
};