![]() |
|
|
#1 (permalink) |
|
Crazy
|
[Javascript] Is this even remotely correct?
Hello.
I am trying to get a website to display a specific thing based on the hour of the day. I *think* this works (I'm a C person myself) but when I drop it into the CMS I'm using it displays nothing. Thoughts? Code:
<script Language="JavaScript">
var today = new Date();
var hours = today.getHours();
var readings = 0;
switch (hours)
{
case 0:
readings = 7;
break
case 1:
readings = 7;
break
case 2:
readings = 7;
break
case 3:
readings = 7;
break
case 4:
readings = 7;
break
case 5:
readings = 7;
break
case 6:
readings = 1;
break
case 7:
readings = 1;
break
case 8:
readings = 1;
break
case 9:
readings = 2;
break
case 10:
readings = 2;
break
case 11:
readings = 2;
break
case 12:
readings = 3;
break
case 13:
readings = 3;
break
case 14:
readings = 3;
break
case 15:
readings = 4;
break
case 16:
readings = 4;
break
case 17:
readings = 4;
break
case 18:
readings = 5;
break
case 19:
readings = 5;
break
case 20:
readings = 5;
break
case 21:
readings = 6;
break
case 22:
readings = 6;
break
case 23:
readings = 6;
break
}
AgpeyaHours = new Array(8);
AgpeyaHours[1]="Prime"
AgpeyaHours[2]="Terce"
AgpeyaHours[3]="Sext"
AgpeyaHours[4]="None"
AgpeyaHours[5]="Vespers"
AgpeyaHours[6]="Compline"
AgpeyaHours[7]="Midnight"
document.write(AgpeyaHours[readings]);
</script>
|
|
|
|
|
#2 (permalink) |
|
Free Mars!
Location: I dunno, there's white people around me saying "eh" all the time
|
I think "break" is suppose to have ; at the end
I'm drunk btw, don't blame me if its the way its suppose to be
__________________
Looking out the window, that's an act of war. Staring at my shoes, that's an act of war. Committing an act of war? Oh you better believe that's an act of war |
|
|
|
|
#3 (permalink) |
|
Lover - Protector - Teacher
Location: Seattle, WA
|
You don't need ; on breaks, in Javascript at least.
This code seems to run fine on my box; I just make a blank html and inserted the Script. This sounds like an issue with your CMS or how this jscript is integrated with your other code (if any). That said, wouldn't it be simpler to write it this way? It seems a bit clunky to make an switch statement for 24 cases when you only have a few options; Code:
<script language="JavaScript">
var today = new Date();
var hours = today.getHours();
if (hours >= 0 && hours < 6)
document.write("Midnight");
else if (hours >= 6 && hours <9)
document.write("Prime");
else if (hours >= 9 && hours <12)
document.write("Terce");
else if (hours >= 12 && hours < 15)
document.write("Sext");
else if (hours >= 15 && hours < 18)
document.write("None");
else if (hours >= 18 && hours < 21)
document.write("Vespers");
else
document.write("Compline");
</script>
__________________
"I'm typing on a computer of science, which is being sent by science wires to a little science server where you can access it. I'm not typing on a computer of philosophy or religion or whatever other thing you think can be used to understand the universe because they're a poor substitute in the role of understanding the universe which exists independent from ourselves." - Willravel Last edited by Jinn; 12-14-2005 at 12:00 AM.. |
|
|
|
|
#4 (permalink) | ||
|
Crazy
|
Quote:
Quote:
Now if only I can get it to work in the CMS ![]() thanks again |
||
|
|
| Tags |
| correct, javascript, remotely |
| Thread Tools | |
|
|