Completely baffled by 'Binary Agents' error

Hi guys,
I’ve been solving the binary agents challenge, where a binary string is first translated to unicode, then English. The code I’ve written looks (messy but) perfect to me, and it works perfectly - for every letter but the first. My first thought was that it’s an array-out-of-bounds thing, but even though I’ve massively debugged it with a million console.log()'s - I haven’t been able to find the problem.

var result = [];
var arr = x.split(" ");
var currentDigit, digit, temp;
//Step one - convert binary to unicode
for(var arrIndex = 0; arrIndex < arr.length; arrIndex++){
  for(digIndex = 7; digIndex >= 0; digIndex--){
currentDigit = arr[arrIndex][digIndex];
temp += (currentDigit * Math.pow(2, 7-digIndex));
  }
  console.log(temp);
  result.push(temp);
  temp = 0;
}
//Step two - convert unicode to English
var final = "";
for(var i = 0; i < result.length; i++){
  final += String.fromCharCode(result[i]);
}
console.log(final);

I appreciate any help you might be able to offer!

Make third line like this:

var currentDigit, digit, temp = 0;
1 Like

Thank you oh so very much, such a silly mistake!