Intermediate Algorithm Scripting: Binary Agents not passing

I wrote the following code for the “Intermediate Algorithm Scripting: Binary Agents” challenge. Result is ok, but it does not pass the test. Any idea why ?

function binaryAgent(str) {
var translation = “”;
for (let i in str.split(" “)) { translation = translation + (”&#" + parseInt(str.split(" ")[i], 2) + “;”) };
console.log(translation);
console.log(typeof translation);
return translation;
};

Attached : screenshot :

You are outputting HTML entities and not letters, have a look at the String method fromCharCode.

Steps:

  1. Split binary values into spaces
  2. Map every element
  3. Parse the element to decimal
  4. Convert the decimal value to its ASCII using Sting.fromCharCode()
  5. Join the ASCII values
    Give it a try.

Spoiler Alert:

str.split(" “).map(el => String.fromCharCode(parseInt(el,2))).join(”")

1 Like

Writing “Spoiler Alert” isn’t super useful. Use the spoiler tags.

[spoiler]This text will be blurred[/spoiler]

Works like this

1 Like