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.