Skip to content

Instantly share code, notes, and snippets.

@hodbby hodbby/gist:2922429
Created Jun 13, 2012

What would you like to do?
Roll the dice
<head><title>Roll the Dice</title></head>
<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);

This comment has been minimized.

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
You can’t perform that action at this time.