Results 1 to 2 of 2

Thread: Java script help

  1. #1
    Join Date
    Oct 2004
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Java script help

    Hi,

    I'm new to javascript, and for my homework for my CS class, I need to write a JS code that'lll display a different image depending on the hour of the day. For instance, from 9am to 5pm, it's image A, but from 5pm to 9am, it must be a different image.

    This assignment requires that I use a conditional, if, and else statments, but I'm confused. I'd appreciate any help.

    Thanks.

    Please help. I'm dying.

  2. #2
    Join Date
    Aug 2004
    Location
    Brighton
    Posts
    1,563
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I've made you a script you can base ideas on.

    Code:
    <script type="text/JavaScript">
    // script by cr3ative @ dynamicdrive.com/forums
    var date = new Date();
    var hours = date.getHours();
    var display_time = (hours);
    if (hours > 9 && hours < 19)
       {
       document.write("<img src='imagea.gif'>");
       }
    if (hours > 19)
       {
       document.write("<img src='imageb.gif'>");
       }
    else
       {
       alert("Data recieved could not be processed");
       }
    </script>
    This way we use if else statements and a conditional, I think.
    Script requires images imagea.gif and imageb.gif

    cr3ative
    Last edited by cr3ative; 10-24-2004 at 09:38 AM.
    A retired member, drop me a line through my site if you'd like to find me!
    cr3ative media | read the stickies

Bookmarks

Posting Permissions

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