PDA

View Full Version : Java script help



keii_san
10-23-2004, 07:37 PM
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.

cr3ative
10-24-2004, 07: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'>");
}
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