I have tried looking for this problem here but still can’t find an answer (maybe I’m too newbie to even write the exact keywords).
I am trying to overcome freecodecamp challenge on “binary agent”, my question is not “How to convert binary to text string” But
why is there a double quote at the beginning of the my result ?
Thank You
function binaryAgent(str) {
let binaryArr;
let decimalArr = [];
let textArr = [];
let joinTextArr;
for (let i=0; i<str.length; i++){
// convert binary to decimal use parseInt(value, radix)
binaryArr = str.split(" ");
decimalArr.push(parseInt(binaryArr[i], 2));
decimalArr = decimalArr.filter( value => !Number.isNaN(value) );
// convert decimal to text
textArr.push(String.fromCharCode(decimalArr[i]))
// join to be a string
joinTextArr = textArr.join("")
}
return joinTextArr;
}
console.log(binaryAgent("01000001 01110010 01100101 01101110 00100111 01110100 00100000 01100010 01101111 01101110 01100110 01101001 01110010 01100101 01110011 00100000 01100110 01110101 01101110 00100001 00111111"));
// result > "Aren't bonfires fun!?