title: Javascript Variable outside of function?
body: <pre><code>1| &lt;script type="text/javascript"&gt;
  2|    function more() {
  3|          $("#innerSub2").animate({ scrollTop: "+=240px" },1000);
  4|          var count = 1;
  5|          document.getElementById("dot" +count).style.color="#c7c9e9";
  6|          var count = count + 1;
  7|          document.getElementById("dot" +count).style.color="#6464c1";
  8|        }
  9|     &lt;/script&gt;
  </code></pre>
  
  <p>Helo, I am pretty new to javascript. So sorry if this is a stupid question.<br>
  On the first click event the variable works as i need it to( line 5, count=1)(line 7, count=2)<br>
  But on second click event i need ( line 5, count=2)(line 7, count=3) but as you can see it resets to 1 with line 4.<br>
  So the question is, how can I declare | var count = 1; | outside of function more() so it won't reset my variable? or if there is any other way to do this..<br>
  Also if there is a way to stop variable count from exceeding 3, please share<br>
  Thank you</p>