Hello Everyone I hope you all doing okay
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);
space++;
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");
console.log(result);
**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: