/    Sign up×
Community /Pin to ProfileBookmark

Playing random sound

Hi,

I have this code:

[code=php]<script type=”text/javascript”>
function playrandom(){
var a=Math.round(Math.random()*12-0.5);
var b=[“A1″,”AS1″,B1″,”C1″,”CS1″,D1″,”DS1″,”E1″,F1″,”FS1″,”G1″,GS1”]
document.getElementById(“thenote”).src=b[a]+”.mid”;
}
</script>

<bgsound id=”thenote”>

</head>

<body onload=”playrandom()”>
</body>[/code]

When you open the page, a random sound should play (either A1.mid, AS1.mid, B1.mid etc).

Thanks,

Neil

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@neil9999authorMay 21.2004 — Don't worry, this line was wrong:

var b=["A1","AS1","B1","C1","CS1","D1","DS1","E1","F1","FS1","G1","GS1"]

Neil
Copy linkTweet thisAlerts:
@dr_johnMay 21.2004 — "Webmaster in a nutshell" doesn't list id as an attribute of <bgsound>

It's a head element, not a body element and I think only body elements have an id.

Just a thought.
×

Success!

Help @neil9999 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...