title: JavaScript: Calling a variable that has been altered within another function?
body: <p>I'm trying to create an alert in JavaScript using cookies that both greets the user by name and tells them how many times they've won a specific game on the website. I have the user greeting working fine, but I can't seem to get the counter to work correctly. It involves calling variables that are altered by a previous function, and I think that's where my problem is, but I'm not sure how to fix that. (The variables are called 'cardOnePoints' and 'cardTwoPoints'.) Can anyone help me with that or tell me if there's anything else I'm doing wrong?</p>
  
  <pre><code>function getCookieOne(c_name) {
  var i, x, y, ARRcookies = document.cookie.split(";");
  for (i = 0; i &lt; ARRcookies.length; i++) {
      x = ARRcookies[i].substr(0, ARRcookies[i].indexOf("="));
      y = ARRcookies[i].substr(ARRcookies[i].indexOf("=") + 1);
      x = x.replace(/^\s+|\s+$/g, "");
      if (x == c_name) {
          return unescape(y);
      }
  }
  }
  
  function setCookieOne(c_name, value, exdays) {
  var exdate = new Date();
  exdate.setDate(exdate.getDate() + exdays);
  var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" +     exdate.toUTCString());
  document.cookie = c_name + "=" + c_value;
  }
  
  var winnerCount = getCookieOne('gamesWonCount') || 0;
  
  function calculateWinnerCount() {
  if (cardOnePoints + cardTwoPoints === 21) {
      winnerCount = winnerCount + 1;
      setCookieOne("gamesWonCount", winnerCount, 365);
  }
  }
  
  function checkCookie() {
  var username = getCookieOne("username");
  
  if (username != null &amp;&amp; username != "") {
      alert("Sup " + username + "!!! Woah man, you've won " + winnerCount + " game(s)!!!");
  } else {
      username = prompt("Please enter your name:", "");
      if (username != null &amp;&amp; username != "") {
          setCookieOne("username", username, 365);
      }
  }
  }
  </code></pre>
  
  <p>You can see my entire code here: <a href="http://jsfiddle.net/hayleyelisa/9padf/2/" rel="nofollow">http://jsfiddle.net/hayleyelisa/9padf/2/</a></p>