Tell us what’s happening:
I’ve been working on a JavaScript algorithm challenge, and I stumbled onto a feature I haven’t learned yet. My console output transforms to a
when I post, so it’s in the title.
What is this?
Is this a specific native library of JavaScript? I know the output is caused by using the fromCharCode() method, but none of these characters are in the ASCII chart.
Your code so far
function binaryAgent(str) {
var word = "";
var sentence = "";
var sum = 0;
var strArr = str.split(" ");
while (strArr.length > 0) {
word = strArr.splice(0, 1).join("").split("");
//console.log(word);
sum = 0;
for (let i = 0; i < word.length; i++) {
sum += (word.pop() * 2 ** i);
}
sentence += String.fromCharCode(sum);
}
console.log(sentence);
return str;
}
binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111");
Your browser information:
User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36
.
Challenge: Binary Agents
Link to the challenge:
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents