0
function addBinary(a,b) {
  var sum = a + b;
  return sum;

  function decToBin(sum) {
    return (sum >>> 0).toString(2);
  }
}
Nick Parsons
  • 45,728
  • 6
  • 46
  • 64

2 Answers2

0
function addBinary(a,b) {
  var sum = a + b;

  //I added this line!
  //Instead of returning "sum", it returns output of "decToBin"
  return decToBin(sum);

  function decToBin(sum) {
    return (sum >>> 0).toString(2);
  }
}
codemirror
  • 3,164
  • 29
  • 42
0

I think this is what you want.

function addBinary(a,b) {
     var sum = a + b;
     return decToBin(sum);

     function decToBin(sum) {
         return dec2bin(sum);
     }
 }

or a shorter one like this.

function addBinary(a,b) {
    var sum = a + b;
    return dec2bin(sum);
}

You can also have negative numbers without a problem.

Cereal Killer
  • 15
  • 2
  • 11