title: Why does function return false after checking only one value in loop
body: <p>Trying to check if a value exists within an array, but my nested if statement is returning 
  false even if the value exists in the array. This worked until I added an else to my loop, now it only works if the value to check for is the first index.</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>var num = [1, 2, 3, 4, 5, 6, 7, 8, 9];
  var inp = parseInt(prompt("Enter a number to see if it is in the array:"));
  
  function checkIfInArray(n, anArray) {
  
    for (var i = 0; i &lt; anArray.length; i++) {
      if (num[i] == n) {
        return true;
      } else {
        return false;
      }
    }
  }
  
  console.log(checkIfInArray(inp, num));</code></pre>
  </div>
  </div>
  </p>