Tilted Forum Project - TFP - Sexuality, Philosophy and Political Discussion

Go Back   Tilted Forum Project - TFP - Sexuality, Philosophy and Political Discussion > Interests > Tilted Technology

Reply
 
LinkBack Thread Tools
Old 12-13-2005, 09:49 PM   #1 (permalink)
Crazy
 
Join Date: May 2004
[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>
TheProf is offline   Reply With Quote
Old 12-14-2005, 12:13 AM   #2 (permalink)
Free Mars!
 
feelgood's Avatar
 
Join Date: Apr 2003
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
feelgood is offline   Reply With Quote
Old 12-14-2005, 12:43 AM   #3 (permalink)
Lover - Protector - Teacher
 
Jinn's Avatar
 
Join Date: May 2005
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>
Just a suggestion.. this will even work if you decide to expand to include the different prayers for each time.. just change the document.write string.
__________________
If you struggle with something your entire life, try harder.
Awareness without action is worthless, and failure is not an accident.

Last edited by Jinn; 12-14-2005 at 01:00 AM.
Jinn is offline   Reply With Quote
Old 12-14-2005, 08:51 AM   #4 (permalink)
Crazy
 
Join Date: May 2004
Quote:
Originally Posted by JinnKai
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).
I came to that conclusion by doing the same thing. It seems to be a problem with how the CMS is running the script.
Quote:
Originally Posted by JinnKai
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;
<snipped great code>
Just a suggestion.. this will even work if you decide to expand to include the different prayers for each time.. just change the document.write string.
Thank you very much! That is far more elegant code than the brute force one I had.

Now if only I can get it to work in the CMS

thanks again
TheProf is offline   Reply With Quote
Reply

Bookmarks

Tags
correct, javascript, remotely

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -7. The time now is 03:28 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
All text (c) 2002-2008 Tilted Forum Project
"Insignia" vBulletin 3.5 - b6gm6n - x7x7x7.com