title: How to code the last visited date and display it using alert() in Javascript?
body: <p>How can I code the "Last Visited Date" and display it using the <code>alert()</code> method?</p>
  
  <p>Here is the JS code:</p>
  
  <p><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>function setCookie(cname,cvalue,exdays) {
   var d = new Date();
   d.setTime(d.getTime() + (exdays*24*60*60*1000));
   var expires = "expires=" + d.toGMTString();
   document.cookie = cname+ "=" + cvalue +"; " + expires;
  }
  function getCookie(cname) {
   var name = cname + "=";
   var ca = document.cookie.split(';');
   for(var i=0; i&lt;ca.length; i++) {
    var c = ca[i];
    while (c.charAt (0)==' ') {
     c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
     return c.substring(name.length, c.length);
    }
   }
   return "";
  }
  
  function checkCookie(){
   var username = getCookie("username");
   if (username != null &amp;&amp; username != "")
   {
    alert("Welcome again " + username);
   }
   else
   {
    username=prompt("Please enter your name:","");
    if (username != null &amp;&amp; username != "")
    {
     setCookie("username",username,365);
    }
   }
  }</code></pre>
  </div>
  </div>
  </p>