Forum Moderators: open
<script language="Javascript">
<!--
now = new Dateif (now.getHours() < 1) {
document.write("Listen Live Now")
}
else if (now.getHours() < 5) {
document.write("Justed missed the show")
}
else if (now.getHours() < 22) {
document.write("Almost on again")
}
else {
document.write("Listen Live Now")
}
//-->
</script>
Though I want a different messages to appear on sunday and monday, does anyone have any idea how to do this?
Thanks,
Here's an example:
<script type="text/javascript">
var now = new Date();
var msg = "";
// Determine what day this is (0 = Sunday, 6 = Saturday)
if (now.getDay() < 2) { // Sunday or Monday
msg = "No show today!";
}
else { // Tuesday through Saturday
var hours = now.getHours();
if (hours < 1) {
msg = "Listen Live Now";
}
else if (hours < 5) {
msg = "Just missed the show";
}
else if (hours < 22) {
msg = "Almost on again";
}
else {
msg = "Listen Live Now";
}
}
// Display the msg to the user
// You should consider changing this to the DOM method. I don't
// know what your markup looks like, otherwise I would have
// done it for this example.
document.write(msg);
</script>
[edited by: Fotiman at 2:52 pm (utc) on June 11, 2007]
I would like to further adapt the script to countdown to when the show is on in minutes and hours, but i am unable to work out how to incoporate two variables. However i was unable to get it to work so added the two scripts seperatley which also has some errors.
<script type="text/javascript">
var now = new Date();
var msg = "";
// Determine what day this is (0 = Sunday, 6 = Saturday)
if (now.getDay() > 5) { // Friday or Saturday
msg = "No show today!";
}
else { // Sunday through Thursday
var hours = now.getHours();
if (hours < 1) {
msg = "Listen Live Now";
}
else if (hours < 2) {
msg = "Live in under 20 Hours";
}
else if (hours < 3) {
msg = "Live in under 19 Hours";
}
else if (hours < 4) {
msg = "Live in under 18 Hours";
}
else if (hours < 5) {
msg = "Live in under 17 Hours";
}
else if (hours < 6) {
msg = "Live in under 16 Hours";
}
else if (hours < 7) {
msg = "Live in under 15 Hours";
}
else if (hours < 8) {
msg = "Live in under 14 Hours";
}
else if (hours < 9) {
msg = "Live in under 13 Hours";
}
else if (hours < 10) {
msg = "Live in under 12 Hours";
}
else if (hours < 11) {
msg = "Live in under 11 Hours";
}
else if (hours < 12) {
msg = "Live in under 10 Hours";
}
else if (hours < 13) {
msg = "Live in under 9 Hours";
}
else if (hours < 14) {
msg = "Live in under 8 Hours";
}
else if (hours < 15) {
msg = "Live in under 7 Hours";
}
else if (hours < 16) {
msg = "Live in under 6 Hours";
}
else if (hours < 17) {
msg = "Live in under 5 Hours";
}
else if (hours < 18) {
msg = "Live in under 4 Hours";
}
else if (hours < 19) {
msg = "Live in under 3 Hours";
}
else if (hours < 20) {
msg = "Live in under 2 Hours";
}
else if (hours < 21) {
msg = "Live in under 1 Hours";
}
else if (hours < 22) {
msg = "Live in";
}
else {
msg = "Listen Live Now";
}
}
// Display the msg to the user
// You should consider changing this to the DOM method. I don't
// know what your markup looks like, otherwise I would have
// done it for this example.
document.write(msg);
</script>
<script type="text/javascript">
var now = new Date();
var msg = "";
// Determine what day this is (0 = Sunday, 6 = Saturday)
if (now.getDay() > 4) { // Sunday or Monday
msg = "";
}
if (now.getHours() > 22) { // Past 10
msg = "";
}
if (now.getHours() < 1) { // Before 1
msg = "";
}
else { // Tuesday through Saturday
var minutes = now.getMinutes();
if (minutes < 1) {
msg = "";
}
else if (minutes < 1) {
msg = "59 mins";
}
else if (minutes < 2) {
msg = "58 mins";
}
else if (minutes < 3) {
msg = "57 mins";
}
else if (minutes < 4) {
msg = "56 mins";
}
else if (minutes < 5) {
msg = "55 mins";
}
else if (minutes < 6) {
msg = "54 mins";
}
else if (minutes < 7) {
msg = "53 mins";
}
else if (minutes < 8) {
msg = "52 mins";
}
else if (minutes < 9) {
msg = "51 mins";
}
else if (minutes < 10) {
msg = "50 mins";
}
else if (minutes < 11) {
msg = "49 mins";
}
else if (minutes < 12) {
msg = "48 mins";
}
else if (minutes < 13) {
msg = "47 mins";
}
else if (minutes < 14) {
msg = "46 mins";
}
else if (minutes < 15) {
msg = "45 mins";
}
else if (minutes < 16) {
msg = "44 mins";
}
else if (minutes < 17) {
msg = "43 mins";
}
else if (minutes < 18) {
msg = "42 mins";
}
else if (minutes < 19) {
msg = "41 mins";
}
else if (minutes < 20) {
msg = "40 mins";
}
else if (minutes < 21) {
msg = "39 mins";
}
else if (minutes < 22) {
msg = "38 mins";
}
else if (minutes < 23) {
msg = "37 mins";
}
else if (minutes < 24) {
msg = "36 mins";
}
else if (minutes < 25) {
msg = "35 mins";
}
else if (minutes < 26) {
msg = "34 mins";
}
else if (minutes < 27) {
msg = "33 mins";
}
else if (minutes < 28) {
msg = "32 mins";
}
else if (minutes < 29) {
msg = "31 mins";
}
else if (minutes < 30) {
msg = "30 mins";
}
else if (minutes < 31) {
msg = "29 mins";
}
else if (minutes < 31) {
msg = "29 mins";
}
else if (minutes < 32) {
msg = "28 mins";
}
else if (minutes < 33) {
msg = "27 mins";
}
else if (minutes < 34) {
msg = "26 mins";
}
else if (minutes < 35) {
msg = "25 mins";
}
else if (minutes < 36) {
msg = "24 mins";
}
else if (minutes < 37) {
msg = "23 mins";
}
else if (minutes < 38) {
msg = "22 mins";
}
else if (minutes < 39) {
msg = "21 mins";
}
else if (minutes < 40) {
msg = "20 mins";
}
else if (minutes < 41) {
msg = "19 mins";
}
else if (minutes < 42) {
msg = "18 mins";
}
else if (minutes < 43) {
msg = "17 mins";
}
else if (minutes < 44) {
msg = "16 mins";
}
else if (minutes < 45) {
msg = "15 mins";
}
else if (minutes < 46) {
msg = "14 mins";
}
else if (minutes < 47) {
msg = "13 mins";
}
else if (minutes < 48) {
msg = "12 mins";
}
else if (minutes < 49) {
msg = "11 mins";
}
else if (minutes < 50) {
msg = "10 mins";
}
else if (minutes < 51) {
msg = "9 mins";
}
else if (minutes < 52) {
msg = "8 mins";
}
else if (minutes < 53) {
msg = "7 mins";
}
else if (minutes < 54) {
msg = "6 mins";
}
else if (minutes < 55) {
msg = "5 mins";
}
else if (minutes < 56) {
msg = "4 mins";
}
else if (minutes < 57) {
msg = "3 mins";
}
else if (minutes < 58) {
msg = "2 mins";
}
else if (minutes < 59) {
msg = "1 mins";
}
else if (minutes < 60) {
msg = "";
}
else {
msg = "";
}
}
// Display the msg to the user
// You should consider changing this to the DOM method. I don't
// know what your markup looks like, otherwise I would have
// done it for this example.
document.write(msg);
</script>
I mentioned the dates wrong above. There are shows on monday to thursday 10pm to 1am (where i want the message displayed 'Radio Show starts in 5hours 6 mins' up until when the show starts and i want 'listen live now') and then for the days when the show isnt on friday and saturday (i would like the message to display 'no show today').
Is this possible in javascipt or in another format (whichever is the simplest and easiest).
Thanks for all your help.