I want JavaScript to translate text in a textarea into binary code.
For example, if a user types in "TEST
Try this:
String.prototype.toBinaryString = function(spaces = 0) {
return this.split("").map(function(character) {
return character.charCodeAt(0).toString(2);
}).join(" ".repeat(spaces));
}
And use it like this:
"test string".toBinaryString(1); // with spaces
"test string".toBinaryString(); // without spaces
"test string".toBinaryString(2); // with 2 spaces