What is the purpose of this string argument in a JavaScript function?

Posted by Adel on Stack Overflow See other posts from Stack Overflow or by Adel
Published on 2012-03-27T05:20:09Z Indexed on 2012/03/27 5:29 UTC
Read the original article Hit count: 178

Filed under:
|

In the following function, there is the line:

var username=getCookie("username");

Here's the whole function:

function checkCookie()
{
var username=getCookie("username");
if (username!=null && username!="")
  {
  alert("Welcome again " + username);
  }
else 
  {
  username=prompt("Please enter your name:","");
  if (username!=null && username!="")
    {
    setCookie("username",username,365);
    }
  }

What is the point of the "username" argument being passed above?

function getCookie(c_name)
{
var i,x,y,ARRcookies=document.cookie.split(";");
for (i=0;i<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);
    }
  }
}

The whole code is here Thanks!

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about homework