/    Sign up×
Community /Pin to ProfileBookmark

Use JavaScript to create a web page that operates like a slot machine. The page should start up with three random pictures next to each other (all the same size). There should be a link below the pictures that causes all three pictures to be randomly chosen again whenever the link is clicked or rolled over. Be sure both clicking and rolling over the link both work. You should have at least five different pictures available.

I’ve tried a variety of things and I can’t get both to work. The only notes my teacher gave us was [url]http://www.kishwaukeecollege.edu/faculty/dklick/cis119/notes20080131.html[/url]

[code=html]
<html>
<head>
<title>Slot Machine</title>
<script type=”text/javascript” language=”javascript”>
pic = new Array();
if (document.images) {
for (i=0; i<4; pic[i++] {
pic[i] = new Image();
pic[i].src= ‘pic’ + i + ‘.jpg’;
} else {
for (i=0; i<4; pic[i++]=””);
document.r1 = document.r2 = “”;
}
}
function test() {
document.r1.src=pic[Math.floor(Math.random()*pic.length)].src;
document.r2.src=pic[Math.floor(Math.random()*pic.length)].src;
document.r3.src=pic[Math.floor(Math.random()*pic.length)].src;
document.r4.src=pic[Math.floor(Math.random()*pic.length)].src;
}
</script>
</head>
<body>
<img src=”pic0.jpg”
width=”100″ height=”125″
border=”0″ name=”r1″ id=”r1″
alt=”max1 picture” />
<img src=”pic2.jpg”
width=”100″ height=”125″
border=”0″ name=”r2″ id=”r2″
alt=”pignose picture” />
<img src=”pic3.jpg”
width=”100″ height=”125″
border=”0″ name=”r3″ id=”r3″
alt=”cuddles picture ” />
<img src=”pic4.jpg”
width=”100″ height=”125″
border=”0″ name=”r4″ id=”r4″
alt=”tiger picture ” />
<!–
<p><a href=”#”
onmouseover=”test();”
onclick=”test(); return false;”></a>
</p>
–>
<p><a href=”#”
onmouseover=”document.r1.src=pic[Math.floor(Math.random()*pic.length].src;”
onmouseout=”document.r1.src=r2.src;”
onclick=”document.r1.src=pic[Math.floor(Math.random()*pic.length].src; return false;”
>Link 1</a></p>
<p><a href=”#”
onmouseover=”document.r2.src=pic[Math.floor(Math.random()*pic.length)].src;”
onmouseout=”document.r2.src=r3.src;”
onclick=”document.r2.src=pic[Math.floor(Math.random()*pic.length].src;return false;”
></a></p>
<noscript>
<p align=”center”>
Please Turn On Java Script If Available
</p>
</noscript>
</body>
</html>[/code]

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ShampieFeb 08.2008 — Start off with this (line 7):

for (i=0; i<4; pic[i++] {

change it to

for (i=0; i<4; pic[i++][COLOR="Lime"]) [/COLOR]{

If I got time I'll go through the rest.. just noticed this instantly.
×

Success!

Help @arby11886 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 6.2,
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: @meenaratha,
tipped: article
amount: 1000 SATS,

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

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...