title: Ruby: Factorial Recursion
body: <p>The difference between the two methods occurs at second if condition. The if condition in the first method is "if num &lt;= 1" and the if condition in the second method is "if num = 1". I mapped out both methods on a piece of paper step by step but I don't understand why the factorial2 returns 1 instead of 6. On paper, I get 6 for both methods.</p>
  
  <pre><code>def factorial1(num)
      if num &lt; 0
          return "Please use a positive number"
      end
  
      if num &lt;= 1
          1
      else
          num * factorial(num-1)
      end
  end
  puts factorial1(3)
  #returns 6
  def factorial2(num)
      if num &lt; 0
          return "Please use a positive number"
      end
  
      if num = 1
          1
      else
          num * factorial(num-1)
      end
  end
  puts factorial2(3)
  #returns 1
  </code></pre>