Saghan Mudbhari
Saghan Mudbhari

Reputation: 17

can't make cookie in javascript

I am new to javascript. I tried to make a cookie that displays cookie if site is visited before, otherwise asks name. I don't know why the script doesn't work. Please help me debug. `

<script type="text/javascript"> 
//-----------
function check()
{
if(document.cookie.length>0){
return document.cookie
}
else
return ""
}
//---------
function get(){
var today=new date()
today.setDate(today+1)
var name=check()
if(name=="")
{name=prompt("name?","")
document.cookie="username="+name+";expires="+today.toUTCString()
}
else
document.write("welcome back"+document.cookie)
}
</script>
</head>
<body >
<script type="text/javascript"> 
get();
</script>
</body> 
</html>`<html> 
this is so frustrating! Passerby already edited the body of this post; your edit must be more substantive to override the current edit.

Upvotes: 0

Views: 62

Answers (1)

grmmph
grmmph

Reputation: 781

var today=new Date();

With Capital D.

Update: Run this code on a localhost.

Upvotes: 1

Related Questions