Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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 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