![]() |
array prints incorrect values
I initialize part of an array, but when I display them, they are incorrect or duplicated.
Here is my code: Code:
Code:
|
just a question before I actually look at your code... is that all that you want to do? Because javascript has a date object that makes these kinds of things quite simple...
Code:
<html> |
... but the answer to your original question is that you shouldn't use leading zeros for numbers, as javascript can convert them to octal numbers. Have a look:
Code:
<script>Code:
prog[0] = "Sunday 00:00"; |
Thanks, that was the problem. Is it documented somewhere that leading zeros should not be used?
The purpose of this exercise is to fill the array with radio program titles (one per hour) so that when someone logs onto our radio station website, it will display "Now playing: The Tom Collins Show ... Click here to listen". I will have to update the script every time the schedule changes, but that's OK. I'll also need to find out how to get the hour of the day for the Eastern time zone (including Daylight times) as well as the day of the week for the Eastern time zone. If I concatenate the day of week with the hour of the day, that should point to the element in the array to display, such as Monday at 1 pm, display message 113 (1 and 13). |
it's not that they shouldn't be used, just that if they are used, it will be assumed that you want to use octals:
https://developer.mozilla.org/en-US/...,_and_literals one thing you might want to be aware of is that the javascript date object will give you the date according to the user's computer, which can be set as far back as 1980 and as far forward as 2099, and anywhere in between (or at least that's the case with mine). So it is better to get the time from the server, which you know should be accurate. It's quite likely that there is a better way to organise your data than a simple array. Depending on how the schedule looks, it may be better to put it into objects, which would look something like this: Code:
<body>you should also search the forum (and the net at large) for existing examples - plenty of people before you have done similar things - it may not be worth reinventing the wheel :thumbsup: |
Thanks for the suggestions; I'll try to implement them ...
|
| All times are GMT +1. The time now is 09:25 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.