Sevir Posted May 22, 2007 Share Posted May 22, 2007 I want to have a text that randomizes on a weekly bases ( eg. week 1, This is the week of vodka, week 2, This is the week of rum, ect) and no text repeats for a year.Thanks ~Sevir Link to comment Share on other sites More sharing options...
pulpfiction Posted May 22, 2007 Share Posted May 22, 2007 One way to do this is to have a array of 52 different srting/messages and then calculate the week number from the current date and display the message. say if Feb 5, 2007 is the 6th week of the year. so arr[6] = "This is the week of vodka" and feb 12th is 7th week and arr[7] = "This is the week of rum" Link to comment Share on other sites More sharing options...
Sevir Posted May 23, 2007 Author Share Posted May 23, 2007 So, I use getdate?I just starting out with J/S and I fear need more tedious instruction, sorry. Link to comment Share on other sites More sharing options...
jesh Posted May 23, 2007 Share Posted May 23, 2007 Take a look at this page if you need some help with any of the various Date functions in java script:http://www.w3schools.com/jsref/jsref_obj_date.aspJust keep in mind that getMonth() returns the month in a zero-based way. That is to say, the first month of the year (January) will be 0 while the 12th month (December) will be 11. This is useful if you have an array of strings because arrays are also zero-based: var messages = new Array();messages[0] = "vodka"; // January's messagemessages[1] = "grogg";messages[2] = "aquavit";messages[3] = "wine";...messages[11] = "gin"; // December's messagevar date = new Date();var month = date.getMonth();alert("This is the month of " + messages[month] + "!"); There aren't any getWeek() methods built into the Date object in javascript. If you want to get the current week, you'll have to figure that out on your own or do a search on Google. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.