title: JavaScript Cookie Visit Count, Last Login Date
body: <p>I'm new to JavaScript and cookies and I'm trying to create one that will display the amount of times someone has visited a site, the last time they visited, and the expiry date of the cookie. </p>
  
  <p>So far I've taken code from W3schools and tried to modify it to my needs with no luck, then I tried <a href="http://www.sitepoint.com/how-to-deal-with-cookies-in-javascript/" rel="nofollow">SitePoint</a>.  What I have now is an amalgamation of both...</p>
  
  <p><strong>JavaScript</strong></p>
  
  <pre><code>function createCookie(name, value, expires) {
      var cookie = name + "=" + escape(value) + ";";
  
      document.cookie = cookie;
  
  function getCookie(name)  {
      var regexp = new RegExp("(?:^" + name + "|;\s*"+ name + ")=(.*?)(?:;|$)", "g");
      var result = regexp.exec(document.cookie);
      return (result === null) ? null : result[1];
  }
  
  function checkCookie()  {
      var visLog = getCookie("visLog");
      var visAmt = 0;
      var logDate = new Date();
      //create lastLog logDate storage
  
  
      if (visLog != null)  {
          visAmt++;
          alert("You've visited this page: " + visAmt + " times." \n
              "Last visited: " + logDate + "." \n
              "This cookie will stop tracking: " + expires);
      }else{
          createCookie("visLog", "visits", "December 31, 2013 12:59:59");
      }
  } 
  </code></pre>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;body onload="checkCookie()"&gt;
  </code></pre>
  
  <p>Edit: Grammar.</p>