I have never written a script, we’ll get that out of the way now… ?
I have downloaded a script and made some modifications to suit my needs. I am wondering, as I am an amateur, if there is a more efficient way of accomplishing this. This script works and does everything I need it to do, but I am just curious.
Its purpose is to randomly select a song, embed it in the page and display the song title:
[CODE]
<!–
//By George Chiang (http://www.abstract.simplenet.com) More JavaScripts here!
//Modified by Jay Stead (http://www.stead.ca)
var title
var sound1=”/music/PavementCracks.asf”
var sound1_title=”Annie Lennox – Pavement Cracks”
var sound2=”/music/nottheone.asf”
var sound2_title=”Daniel Bedingfield – If You’re Not The One”
var sound3=”/music/onahigh.asf”
var sound3_title=”Duncan Sheik – On a High”
var sound4=”/music/eachday.asf”
var sound4_title=”Ronan Keating – Lovin’ Each Day”
var sound5=”/music/boysofsummer.asf”
var sound5_title=”DJ Sammy – The Boys of Summer”
var x=Math.round(Math.random()*4)
if (x==0) x=sound1
else if (x==1) x=sound2
else if (x==2) x=sound3
else if (x==3) x=sound4
else x=sound5
document.write(‘<embed src=”‘+x+'”hidden=”true” autostart=”true” nosave=”true”>’)
if (x == sound1) document.write(‘<small class=”min”>You are listening to: ‘+sound1_title+'</small>’)
else if (x == sound2) document.write(‘<small class=”min”>You are listening to: ‘+sound2_title+'</small>’)
else if (x == sound3) document.write(‘<small class=”min”>You are listening to: ‘+sound3_title+'</small>’)
else if (x == sound4) document.write(‘<small class=”min”>You are listening to: ‘+sound4_title+'</small>’)
else if (x == sound5) document.write(‘<small class=”min”>You are listening to: ‘+sound5_title+'</small>’)
//–>
Any help appreciated!
Jay