← Back to challenges

Don't Roll Doubles!

JavaScriptHardarraysalgorithmsgamesloops

Instructions

John is playing a dice game. The rules are as follows.

  1. Roll two dice.
  2. Add the numbers on the dice together.
  3. Add the total to your overall score.
  4. Repeat this for three rounds.

But if you roll DOUBLES, your score is instantly wiped to 0 and your game ends immediately!

Create a function which takes in a matrix as input, and return John's score after his game has ended.

Examples

diceGame([[1, 2], [3, 4], [5, 6]]) ➞ 21

diceGame([[1, 1], [5, 6], [6, 4]]) ➞ 0

diceGame([[4, 5], [4, 5], [4, 5]]) ➞ 27

Notes

  • Ignore all other arrays in the matrix if a throw happens to be doubles and go straight to returning 0.
  • John only has two dice and will always give you outcomes for three rounds.
javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: The Collatz Conjecture