View Full Version : Java script help

10-23-2004, 08:37 PM

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.


Please help. I'm dying.

10-24-2004, 08:55 AM
I've made you a script you can base ideas on.

<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'>");
alert("Data recieved could not be processed");

This way we use if else statements and a conditional, I think.
Script requires images imagea.gif and imageb.gif