PDA

View Full Version : random msg


mattover-matter
03-25-2003, 06:55 AM
Hi! Me STILL a n00b at JS so, I need a little help on this. How can I write a random msg from an array of them?



var msg=new array()
msg[1] = "msg 1"
msg[2] = "msg 2"
msg[3] = "msg 3"
msg[4] = "msg 4"
msg[5] = "msg 5"

then

document.write("msg[rand*msg]")

or something. :o Thanks

fshiu
03-25-2003, 08:11 AM
document.write(msg[Math.floor(Math.random()*msg.length)])