Created
June 13, 2012 06:56
-
-
Save hodbby/2922429 to your computer and use it in GitHub Desktop.
Roll the dice
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tml> | |
<head><title>Roll the Dice</title></head> | |
<body> | |
<script type="text/javascript"> | |
var die1 = Math.floor(Math.random()*6 + 1); | |
var die2 = Math.floor(Math.random()*6 + 1); | |
var score; | |
// This time if either die roll is 1 then score should be 0 | |
document.write ("This is role the dice with few rules:</br> If at least one of the rolls is 1 then score should be 0.</br> "); | |
document.write ("If both rolls are equal, multiply one in the other.</br> "); | |
document.write ("else you see the sum. </br>"); | |
document.write ("<b>Refresh to see each time a new score.</b></br> "); | |
score = die1 === 1 || die2 === 1 ? 0 : die1 === die2 ? die1*die2 : die1 + die2; | |
document.write("You rolled a "+die1+" and a "+die2+" for a score of "+score); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
make sure you know the difference between == and === (its very nice to know that ;-))