A JavaScript game of slots.

2017-05-06 05_27_37-Slots.png

Speaking of one-click JavaScript games, here’s my take on the classic slots game. It basically generates three small numbers at random, and if they all match, you win. Simple.

<!DOCTYPE html>
<html>
<head>
<title>Slots</title>
</head>
<body>
<table border="1">
<tr>
<td><p id="a">?</p></td>
<td><p id="b">?</p></td>
<td><p id="c">?</p></td>
</td>
</tr>
</table>
<td><p id="d">SPIN THE SLOTS</p></td>

<button onclick="myFunction()">Spin</button>

<script>
function myFunction()
{
var aa=Math.floor((Math.random()*2)+1);
var bb=Math.floor((Math.random()*2)+1);
var cc=Math.floor((Math.random()*2)+1);

if (aa==bb && bb==cc)
  {
document.getElementById("d").innerHTML="WIN";
}
else
{
document.getElementById("d").innerHTML="LOSE";
}

document.getElementById("a").innerHTML=aa;
document.getElementById("b").innerHTML=bb;
document.getElementById("c").innerHTML=cc;
}
</script>

</body>
</html>

In a future version I will make gold coins fall from your screen.

Leave a Comment

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s