ive created a dice game. The idea is simple. there are three images. two are of 6 sided dice and the other image reads "roll the dice". you click roll the dice and two random dices images are displayed, for example a two and 5 making 7. you can keep clicking roll the dice and the images will change each time. I want to add a prompt box where a user is to guess the outcome of the dice, this i know how to do, however this is where my problem comes in... if the user guesses 7 and the dice rolls anything other than 7 i want it to display a sorry you lose message. and if the user guesses right i want a congratulations you win message. i have seperated my javascript from my html page. this is the code i have so far.
HTML
and the javascript is...Code:<html> <head> <title>The Dice Game </title> </head> <body> <img src="dice1.jpg" id="di1" /> <img src="dice2.jpg" id="di2" /> <img src="roll.jpg" id="dice" title="roll" onclick="rolldice(); return false;"/> <script type="text/javascript" src="dice.js"> </script> </body>
any help with how to do this would be greatly appreciated.Code:var image =[ "dice1.jpg", "dice2.jpg", "dice3.jpg", "dice4.jpg", "dice5.jpg", "dice6.jpg", ]; function rolldice() { var dice = Math.floor(Math.random() * (image.length+1)); document.getElementById("di1").src = image[dice]; var dice = Math.floor(Math.random() * (image.length+1)); document.getElementById("di2").src = image[dice]; } var guess = prompt("What is your guess?")



Reply With Quote


Bookmarks