Binary Agents javascript challenges

Tell us what’s happening:
I trying to return the array after it has been modified with the join method of the array. But for some reason it reads as undefined after my forEach statement. I don’t know what is going on

Your code so far


function binaryAgent(str) {

  var strArray = str.split(" ");
// String charCodeAt
// String fromCharCode

strArray = strArray.forEach(function(element){
   String.fromCharCode(Number.parseInt(element, 2))
})

// for some reason my strArray variable goes undefined after this point
  
return strArray.join(" ");
}

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 (Macintosh; Intel Mac OS X 10_14_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/intermediate-algorithm-scripting/binary-agents

The strArray.forEach doesn’t return anything to assign to strArray. You might want too look at .map instead. Once you get that bit sorted, you’ll still have a bit more work to do to get everythign passing.

1 Like