-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtext-binary-knit-converter.js
37 lines (25 loc) · 1 KB
/
text-binary-knit-converter.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
const secretMessageFrom = document.querySelector('.secret-message');
// let textMessageInput = document.querySelector('.text-message-input')
let binaryMessageOutput = document.querySelector('.binary-message-output')
// display user's message in .textMessage
// function ascii to binary
function textToBinary(str) {
let arrayText = []
let binaryResult = []
for (let i = 0; i < str.length; i++) {
arrayText.push(str.charCodeAt(i))
}
for (let i = 0; i < arrayText.length; i++){
let binary = arrayText[i].toString(2);
binaryResult.push(binary);
}
binaryResult = binaryResult.join(" ");
console.log(binaryResult)
}
// function binaryToKnitPurl binary to knit/purl -> 1 = k, 0 = p
// function binaryToChart binary to knitting graph -> 1 = coloured rectangle, 0 = blank rectangle
secretMessageFrom.addEventListener('submit', function(evt) {
evt.preventDefault();
let str = textMessageInput.value;
binaryMessageOutput.innerText = binaryResult;
});