Tell us what’s happening:
I’m not passing any tests and I’m returning nothing but question mark symbols or empty character boxes. I’m not exactly sure what step I’m missing because I think I have a logical setup. (Transform into array, loop through and convert to integer then to alphabet equivalent of that integer.)
My ideas:
- It’s HOW I’m doing it. But I don’t know how my method is inappropriate.
- I should be using something else instead of
parseInt()
. I triedcharCodeAt()
and it only returned binary so I triedparseInt
. I also think I’m missing a step, but I think I’ve taken care of all necessary conversions…
Your guidance would be much appreciated.
Thank you.
Your code so far
function binaryAgent(str) {
//global variable
let final = [];
let add = [];
//transform string into an array
let neu = str.split('');
//loop through new array and transform each element into an integer using parseInt with base-2 in order to convert from binary
for(let i = 0;i < neu.length; i++){
add.push(parseInt(neu[i], 2));
//Convert from UTF integer to alphabet symbol
final.push(String.fromCharCode(add[i]))
console.log(final)
}
return final;
}
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/73.0.3683.103 Safari/537.36
.
Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents