Binary Agents Challenge Fail

Hello Everyone I hope you all doing okay :grinning: :ok_hand:

I need some help with this challenge can someone please explain to me what I’m doing wrong in my code?

I know the code isn’t that great and if the spaces between the binary numbers were two or there are no spaces that will mess up the conversion step and the result will be wrong after all.

So should my Code be enough to pass the challenge but there is something wrong that I’m not seeing? or should I find another way to solve it?

   **Your code so far**

function binaryAgent(str) {

 let newStr = '';
 let tempStr = '';
 let result = ''
 let space = 0;

for (let i = 0; i < str.length;){
tempStr = str.slice(i + space , i + 8 + space);
newStr = parseInt(tempStr, 2).toString(10) + ' ';
result += String.fromCharCode(newStr);

i = i + 8;
 return result;

let result = binaryAgent("01001001 00100000 01101100 01101111 01110110 01100101 00100000 01000110 01110010 01100101 01100101 01000011 01101111 01100100 01100101 01000011 01100001 01101101 01110000 00100001");
   **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36

Challenge: Binary Agents

Link to the challenge:

Looks like there are some characters in the result string that are not visible. Take a look at the lengths, result of the example in the code has length 23, but including spaces there should be 20 characters.

1 Like

Thanks for the help my friend you were correct that the length is 23 and it supposes to be less.

I discover that there are 3 NaN characters added after the word is translated so I solved it by not letting any NaN characters be added to the results.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.