title: Sort an array with the sort method in javascript
body: <p>I have written this code but it isn't working . It's displaying the unsorted array as well as the button but when I click on the button nothing happens.
  I am new to javascript. What I know so far is that we can call functions using the onclick method by javascript. We can write functions as we write in c or c++ . That's what I think I have done here but it isn't showing the sorted array . </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var myarray = [4, 6, 2, 1, 9, ];
  document.getElementById("demo").innerHTML = myarray;
  
  function sort(myarray) {
    var count = array.length - 1,
      swap,
      j,
      i;
  
    for (j = 0; j &lt; count; j++) {
      for (i = 0; i &lt; count; i++) {
        if (array[i] &gt; myarray[i + 1]) {
          swap = myarray[i + 1];
          myarray[i + 1] = myarray[i];
          myarray[i] = swap;
        }
      }
      document.write(myarray);
    }
  }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;p&gt;Click the button to sort the array.&lt;/p&gt;
  &lt;button onclick="sort()"&gt;Try it&lt;/button&gt;
  &lt;p id="demo"&gt;&lt;/p&gt;</code></pre>
  </div>
  </div>
  </p>