function addBinary(a,b) {
  var sum = a + b;
  return sum;
  function decToBin(sum) {
    return (sum >>> 0).toString(2);
  }
}
            Asked
            
        
        
            Active
            
        
            Viewed 38 times
        
    0
            
            
         
    
    
        Nick Parsons
        
- 45,728
- 6
- 46
- 64
- 
                    You have not called decToBin function. – codemirror Nov 21 '19 at 04:10
- 
                    Does this answer your question? [How do I convert an integer to binary in JavaScript?](https://stackoverflow.com/questions/9939760/how-do-i-convert-an-integer-to-binary-in-javascript) – Cereal Killer Nov 21 '19 at 04:11
2 Answers
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
