Results 1 to 3 of 3

Thread: Welcome!

  1. #1

    Thread Starter
    Hyperactive Member vbzero's Avatar
    Join Date
    Aug 2000
    Location
    Vienna
    Posts
    347

    Question Welcome!

    I want to welcome the user on my website depending on the current time.

    I.e. it's 03:00 in the morning - a textline "Good Morning!" should be drawn by a script.

    When it's 12:00 then it should say "Good Day!" and at 20:00 it should say "Good Evening!".

    thx in advanced!

  2. #2
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    Code:
    <script>
    var today = new Date();
    var hours = today.getHours();
    
    if (hours == 3) document.write("Good morning!");
    else if (hours == 12) document.write("Good day!");
    else if (hours == 20) document.write("Good evening!");
    </script>
    Alcohol & calculus don't mix.
    Never drink & derive.

  3. #3
    Fanatic Member Wynd's Avatar
    Join Date
    Dec 2000
    Location
    In a bar frequented by colossal death robots
    Posts
    772
    P.S. If you want a range of hours, then just use < and >. For example,

    Code:
    <script>
    var today = new Date();
    var hours = today.getHours();
    
    if (hours <= 12) document.write("Good morning!");
    else if (hours <= 20) document.write("Good day!");
    else document.write("Good evening!");
    </script>
    Alcohol & calculus don't mix.
    Never drink & derive.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width