Tell us what’s happening:
Describe your issue in detail here.
I created this code for the program that gives a sentence from its binary equivalent and the results that I am getting are completely correct but the site shows its wrong, why is it happening?
I extracted those numbers from the string and then I calculated their decimal value by using a while loop and then I used String.fromCharCode function to finf the characters and then i added it to a string and returned it.
What is wrong in my code or in my logic? Any help will be fruitful to me
function binaryAgent(str) {
let str1="";
let str2="";
let s=0;
for(let i=0;i<str.length;i++){
str2=str2+str[i];
if(str[i]==" " || i==str.length-1){
s=parseInt(str2);
str2="";
}
let p,r,n=0;
let v=0;
while(s>0){
p=parseInt(s/10);
r=s%10;
n=n+r*Math.pow(2,v);
s=p;
v++;
}
str1=str1+String.fromCharCode(n);
s=0;
}
console.log(str1);
return str1;
}
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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.55 Safari/537.36 Edg/96.0.1054.41
Challenge: Binary Agents
Link to the challenge: