title: Checking for prime number in ruby
body: <p>I am trying to write a method that takes a number and checks if its a prime number. After doing some research a fast way to check is to divide the number by every number between 2 and sqrt(number we are checking). I want my method to return true if it is a prime number and false if it isn't.</p>
  
  <p>So I tried to write code that made logical sense to me but I am getting an error. Here's what I have written:</p>
  
  <pre><code>def PrimeTime(num)
      counter = 2
      while counter &lt;= Math.sqrt(num).ceil
          (counter == Math.sqrt(num).ceil) ? "false"
          (num % counter == 0) ? "true" : counter += 1
      end
  end
  </code></pre>
  
  <p>This gives me</p>
  
  <pre><code>(eval):429: (eval):429: compile error (SyntaxError)
  (eval):422: syntax error, unexpected '\n'
  </code></pre>
  
  <p>Rewritten code</p>
  
  <pre><code>def prime?(num)
      (2..Math.sqrt(num).ceil).to_a.each do |number|
          if num % number == 0
              return false
          else
              return true
          end
      end
  end 
  </code></pre>
  
  <p>FYI, this is not homework. I am going through coderbyte problems. Any help is appreciated!</p>