title: Dividing recursively with only subtraction --- not being able to handle decimals
body: <p>I'm practicing my math/algorithm skills and am trying to divide two numbers using only subtraction. I'm pretty close, but I can't seem to handle decimals and I don't know why? In the lowest level of the stack, when I call divide(9,2), I notice that I'm returning "0", when in fact I want to return 1/2 - but without using the division operator... inside the if x is less than y check, should I add that logic in a subroutine? I'm stuck on how to recursively add numbers after the decimal up to three places. </p>
  
  <pre><code>    var divide = function(x, y) {
          //the number of times you need to subtract y from x.
  
        if (y === 0) {
          return 0
        } 
        // if 
        if (x - y === 0) {
          return 1;
        } 
        if (x &lt; y) {
      // if this is the case, get the value of y - x.  -&gt;1
      var diff = y - x;
      console.log(diff);
      // add a zero to the end --&gt; so in our case, 10
      diff = String(diff) + '0';
      console.log(diff);
      diff = Number(diff);
      console.log(diff);
      // is that now divisible by y? is so how many times? in our case, 5 times.
      var decimal = Number(divide(diff, y));
      var number = "." + decimal;
      //so add .5 to it.
      return number;
    } else {
          return (1 + divide(x - y, y)); 
        }
  
      };
  
      var modulo = function(x, y) {
  
        var val = x;
        while (val &gt;= y) {
          val -= y;
  
        }
        return val;
  
      };
  </code></pre>