Problems › TypeScript › games
Score a dice pair
Roll two dice and sum them. If the two dice match, the pair doubles in value.
- The base score is the sum of both dice.
- When both dice show the same face, the total is doubled.
dicePair(firstRoll: int, secondRoll: int) → int
Where you start
function dicePair(firstRoll: number, secondRoll: number): number {
}
Worked examples
| Call | Result |
|---|---|
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 TypeScript
function dicePair(firstRoll: number, secondRoll: number): number {
let sum = firstRoll + secondRoll;
if (firstRoll === secondRoll) sum *= 2;
return sum;
}