greeting lightbox

Hi,

I create a lightbox in my site that greeting the visitors when they enter to my site

However, I want from the the (Heading 1 “it’s id called ‘demo’”) to make a greeting according to the time system

for example :
1- when the time is from 10 am to 12 pm the (heading 1) will be " morning " like that

2- when the time is from 12 pm to 4 pm the (heading 1) will be " afternoon " like that

and so on

so, what is the code snippet that make the text change automatically according to the time system

by the way thank you for your fast respond for my questions

  • Eyad

So do something like:

$w.onReady(() => {
    let greeting = "";
    const hour = new Date().getHours();
    switch(true){
        case (hour >= 18):
            greeting = "Good evening!";
            break;
        case (hour < 12):
            greeting = "Good morning!";
            break;
        case (hour > 11 && hour < 18):
            greeting = "Good afternoon!";
            break;
    }
    $w("#text1").text = greeting;
})