title: function isPrimeNumber in javascript
body: <p>I want to check if a number is a prime number by typing it in a box, then click on a button and get the value is prime number or is not a prime number. I have the following code, but for some reason I can't figure it out why it is not working - I get the value is prime number for any number I tried. </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function isPrimeNumber() {
    var n = document.getElementById("n").value;
    for (var i = 2; i &lt; n; i++) {
      if (n % i === 0) {
        document.getElementById("result").value = "not a prime number";
      }
    }
    document.getElementById("result").value = "prime number";
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form&gt;
    &lt;p&gt;
      &lt;input type="text" id="n"&gt;
      &lt;input type="button" value="Check if I am prime!" onclick="isPrimeNumber();"&gt;
      &lt;input type="text" id="result"&gt;
    &lt;/p&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>Thanks in advance!</p>