Dice Game in Codecademy

In Codecademy, I completed the Dice Game, and here it is for all to see. The rules of this virtual game are simple: You have two die, and rolling them give you a certain score. Rolling a one on either dice is bad, and results in a score of zero for the particular 'one' dice. If you roll a double, that is two die with the same number, then your score is doubled. Otherwise your score is just one dice added to the other. Quite boring to play after a while, but quite fun to create.

var die1 = Math.floor(Math.random()*6 + 1);
var die2 = Math.floor(Math.random()*6 + 1);
var score;

if (die1 === 1 || die2 === 1) {
    score = 0;
}

else {
  if (die1 = die2) {
      score = die1 + die2 + die1 + die2;
  }

  else {
      score = die1 + die2;
  }
}

console.log("You rolled a "+die1+" and a "+die2+" for a score of "+score);

An example of an outcome would be:

"You rolled a 2 and a 2 for a score of 8"

But the outcome changes everytime due to the random numbers created.

This entry was posted in Computing and tagged , , . Bookmark the permalink.

Leave a reply