I’m a little (not a lot) more than a beginniner at using JavaScript to various things, but I can’t figure out a way to randomize a list of elements and get the result to print. I was trying to combine Math.random, an array of the elements i want to randomize, and an iteration with document.write, but I got nowhere. Any suggestions are appreciated.
- No trackbacks yet.
#1 by jake cigar™ is retired at June 29th, 2009
Just used this code to randomize pictures of my puppy!
hrefs.sort(function(){ return Math.round(Math.random()) -0.5})
hrefs was my array.
UPDATE:
you then loop through the array, and writeln the links…
do you need a program to update in place or demand? that’s harder but can be done.
#2 by Bryan A at June 29th, 2009
Looks like you were on the right track. At the bottom of this site is code on how to create an alert box with a random quote, you should be able to modify it from there.http://www.pageresource.com/jscript/jran…