Binary Agent challenge Help

Binary Agent challenge Help
0

#1

Hey community, I can’t understand Why I’m unable to pass this challenge. It works just as intented, returning a string translated in english from the binary.

function binaryAgent(str) 
{
  var codeASCII=[],bincode,sum,power, reduce,stringAscii=[],curCode;
  str=str.split(" ");
  for(var i=0; i<str.length; i++)
    {
        bincode=str[i];
        sum=0;
      for(var j=0; j <bincode.length ;j++)
        {
             reduce=7-j;
             if(bincode[reduce] === "1")
             {
               power=Math.pow(2,j);
               sum=sum+power;        
             }
        }
       codeASCII.push(sum);
    }
  
  
  
  for( i=0; i<codeASCII.length;i++)
     { 
        curCode=String.fromCharCode(codeASCII[i]);
        stringAscii.push(curCode);
     }
      
  stringAscii=stringAscii.join(" ");
  str=stringAscii;
 return str;
}

For binaryAgent(“01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111”); it returns “Aren’t bonfires fun!?”


#2

You are adding spaces between all the characters with stringAscii=stringAscii.join(" ");
It looks like the escape character is also being included in the final string.


#3

What is the escape character?


#4

\ is there to escape the single quote in “Aren’t”


#5

I see, thanks for pointing that out. What alternatives do I have to convert the array of characters into a String instead of String.join()?


#6

String.join() is fine, but the way you’re using it puts a space in between every character.