Scripts
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb Site ManagementScripts

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 1st, 2011, 08:28 PM
mortonmoore mortonmoore is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2011
Posts: 1 mortonmoore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 m 17 sec
Reputation Power: 0
Smile Quote that changes weekly

I was told javascript may be an option that would work but wanted to hear your advice.

I want to show a quote on a website for one week and then change to another quote a week later, say every Monday it changes? I have 52 quotes for the year. Im not sure how to write it up? I also wanted the first letter of the Quote to be a large letter to make it look funky.

Someone helped me with this below but this way just changes random when the page is refreshes. not really what I want.

Can you please help me and show me where about top paste it in Html. thanks.

<script type="text/javascript">
verses =
[
"quote 1",
"quote 2",
"quote 3",
"quote 4",
"quote 5",
]
var keyword = verses[Math.floor(Math.random()*verses.length)]

document.write(keyword);
</script>

thanks

Reply With Quote
  #2  
Old November 1st, 2011, 11:52 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,944 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 10 h 16 m 54 sec
Reputation Power: 7053
It randomly changes because your index into the verses array is based on Math.random(); if you want to display a new quote for each week of the year you need to base it on the current date instead.

JavaScript has a Date object that you can use to fetch information about the current date. Unfortunately, the week of the year isn't part of that information, although you could program code to calculate it if you want.

The modulo operator (%) can be used to restrict a value to a certain range.

Code:
var now = (new Date()).getTime();
var index = Math.round(now/3600000.0) % verses.length;
var keyword = verses[index];

For example, this code will take the current timestamp in milliseconds [now], divide it by 3600000.0 milliseconds (one hour), then divide it by the number of quotes you have [verses.length] and take the remainder (using the modulo operator).

Effectively, this produces a number (index) between 0 and 4 that increases to the next number once per hour and wraps back around to 0 after it exceeds 5. This number can be used as an index into your verses array.

For an approximate solution you could change 3600000.0 so that it represents 7 days in milliseconds instead of 1 hour in milliseconds. Then you would have code that cycles through a list of quotes, moving to the next one approximately once a week.

A more precise solution is possible of course, but requires more effort because you will need to compute the current week of the year.
__________________
PHP FAQ
How to program a basic, secure login system using PHP
Connect with me on LinkedIn


Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb Site ManagementScripts > Quote that changes weekly

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap