Showing a personal greeting without having to log in

I’m pretty new at Javascript and I’ve been doing researching but since I literally just started, I have no idea what to look for… Anyways I basically want to ask for a user’s name only once and save it as a variable to use with this code so it will say Good Morning…“Andrew!” etc.

I’d like it to save without having to log in but I don’t want a “What’s your name” to pop up every time they visit the index. So would that be a conditional or something where there’s no pop up if it has a value from a previous visit? Thank you!

if (new Date().getHours() < 11) {
    document.getElementById("greeting").innerHTML = "Good morning!";
} else if (new Date().getHours() < 19) {
    document.getElementById("greeting").innerHTML = "Good day!";


You can ask the user their name on their first visit, then save the value provided in a cookie, or localStorage, so that you don’t have to re-prompt them on future visits.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.