Drill

ProblemsJavaScript › games

Score a dice pair

easygamesJavaScript

Roll two dice and sum them. If the two dice match, the pair doubles in value.

dicePair(firstRoll: int, secondRoll: int) → int

Solve it in the editor →

Where you start

function dicePair(firstRoll, secondRoll) {
  
}

Worked examples

CallResult
dicePair(6, 6)24
dicePair(3, 4)7
dicePair(1, 1)4
dicePair(2, 5)7

Hint

Sum first, then check for a double.

Reference solution in JavaScript
function dicePair(firstRoll, secondRoll) {
  let sum = firstRoll + secondRoll;
  if (firstRoll === secondRoll) sum *= 2;
  return sum;
}

The same problem in another language

More games problems in JavaScript