View Single Post
Old 06-08-2012, 07:35 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,036
Thanks: 197
Thanked 2,411 Times in 2,389 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Change this line to
Code:
var dayName = new Array("Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat");
Day 0 is Sunday, Day 6 is Saturday.

To avoid repetition you need to shuffle your colors into a new order:-

Code:
<script type="text/javascript">

Array.prototype.shuffle = function() {
var s = [];
while (this.length) s.push(this.splice(Math.random() * this.length, 1)[0]);
while (s.length) this.push(s.pop());
return this;
}

var colors = new Array("aqua","blue","fuchsia","lime","magenta","navy","purple","red","white","yellow","black");
colors.shuffle();

alert (colors);  // the shuffled array

for (var i =0; i<colors.length; i++) {
alert (colors[i]);
}

</script>
As has often been stated in this forum, document.write() is in effect obsolete. document.write() statements must be run before the page finishes loading. Any document.write() statement that runs after the page finishes loading will create a new page and overwrite all of the content of the current page (including the Javascript which called it). So document.write() is at best really only useful to write the original content of your page. It cannot be used to update the content of your page after that page has loaded. Use DOM methods instead.

Quote:
I am new to java..
Be aware that Java and Javascript are entirely different programming languages, in spite of the confusingly similar names. Rather like Austria and Australia!


"Let us be thankful for the fools. But for them the rest of us could not succeed. " - Mark Twain, US humorist, novelist, short story author, & wit (1835 - 1910)
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 06-08-2012 at 07:50 PM..
Philip M is offline   Reply With Quote
Users who have thanked Philip M for this post:
IMayNeed (06-09-2012)