Binary Agents correct answer being denied

Hey guys, can you help me find out what is wrong with the code below?

I tried everything that I could think of and read other topics related with this challenge, but couldn’t find a satisfactory answer to why my code isn’t accepted even though it return the messages as expected.

function binaryAgent(str) {
  let arr = []
  arr = str.split(' ')
  str = ''
  arr.forEach(elem => {
    str += parseInt(elem, 2) + ' '
  })
  arr = str.split(' ')
  str = ''
  arr.forEach(elem => {
    str += String.fromCharCode(elem)
  })
  return str
}

Thanks!

Take a closer look at the arr after the second time str is split. There’s additional blank element at the end, which somehow makes into the result string.

1 Like

Thank you! After your reply I’ve checked the arr after the first split and it’s returning

[
  '73',  '32',  '108', '111',
  '118', '101', '32',  '70',
  '114', '101', '101', '67',
  '111', '100', '101', '67',
  '97',  '109', '112', '33',
  ''
]

I have an empty string as the last position and it happened because I’ve concatenated a space at the end of parseInt…

It was something simple, but I really appreciate your help! :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.