I'm trying to set cookies in an easy code example, but they don't work as I expect. The problem is that the code doesn't work, it never says "Welcome again Nemo!" Can you help me please? What i am doing wrong? Thank you very much for your time!!!
<script>
function getCookie() {
var name = document.cookie.split('=')
if (name[1] != "" && name[1] != null){
return name[1];
}else{
return "";
}
}
function checkCookie() {
var username=getCookie();
if (username!="") {
alert("Welcome again " + username);
}
else{
username = prompt("Please enter your name:");
if (username != "" && username != null) {
document.cookie = "Username=" + username;
}
}
}
checkCookie();
</script>