title: passing min and max variables to another function
body: <p>I am storing numbers into an array and finding the min and max of the array. the problem is that result isn't reliable. eg. when I store these numbers 15, 20, 5, 30, the expected result should be max:30 and min:5 but instead, the result is max: 5 min: 15.
  any help would be appreciated.
  <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 array = [];
  
  function addNum() { 
      var num = document.getElementById("input").value;
      array.push(num);
      document.getElementById("input").value = null;
      document.getElementById("confirmation").innerHTML = "Num " + num + " has been entered.";
    document.getElementById("array").innerHTML = "array: " + array;
  }
  
  function clearArray() {
      array.splice(0, array.length); //empties array
  }
  
  function findMax(array) {
      var highest = array[0];
      for (var i = 0; i &lt; array.length; i++) {
          if (array[i] &gt;= highest) {
              highest = array[i];
          }
      }
      return highest;
  }
  function findMin(array) {
      var lowest = array[0];
      for (var i = 0; i &lt; array.length; i++) {
          if (array[i] &lt; lowest) {
              lowest = array[i];
          }
      }
      return lowest;
  }
  function findMinMax() {
    var max = findMax(array);
    var min = findMin(array);
    console.log("max: " + max);
    console.log("min: " + min);
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;body&gt;
      &lt;div class="container"&gt;
          &lt;input id="input" type="text" required="required" /&gt;
          &lt;input id="submitbutton" type="button" value="Add" onClick="addNum();" /&gt;
          &lt;input id="clearbutton" type="button" value="Clear" onClick="clearArray();" /&gt;
          &lt;button onclick="findMinMax()"&gt;Find MinMax&lt;/button&gt;
          &lt;p id="array"&gt;&lt;/p&gt;
          &lt;p id="confirmation"&gt;&lt;/p&gt;
          &lt;div id="display"&gt;
              &lt;p id="array"&gt;&lt;/p&gt;
              &lt;p id="lowest"&gt;&lt;/p&gt;
              &lt;p id="highest"&gt;&lt;/p&gt;
          &lt;/div&gt;
    &lt;/div&gt;
  &lt;/body&gt;</code></pre>
  </div>
  </div>
  </p>