Skip to content

Instantly share code, notes, and snippets.

@hodbby
Created June 13, 2012 06:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hodbby/2922429 to your computer and use it in GitHub Desktop.
Save hodbby/2922429 to your computer and use it in GitHub Desktop.
Roll the dice
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>
@nudnic
Copy link

nudnic commented Jun 30, 2012

make sure you know the difference between == and === (its very nice to know that ;-))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment