Couple thing, I think the getCookie2 and setCookie2 are redundant. and this line should be setCookie("pet", pet, 30); instead of setCookie("pet", user, 30);
function checkCookie() {
var user = getCookie("username");
var pet = getCookie("pet");
if (user != "") {
alert("Welcome again " + user + ' and your pet: ' + pet);
document.getElementById("demo").innerHTML = "Welcome back, " + user;
document.getElementById("d").innerHTML = "Your pet name, " + pet;
} else {
user = prompt("Please enter your name:", "");
pet = prompt("Please enter your pet name:", "");
if (user != "" && user != null) {
setCookie("username", user, 30);
setCookie("pet", pet, 30);
}
}
}
Output:
Welcome back, myname
Your pet name, mypet