Reputation: 17
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