← Back to challenges

Chance of a Specific Sum for N Dice

JavaScriptHardalgorithmsgamesloopsmath

Instructions

Given the number of dices and the sum we want to get the chance of, return the chance rounded to 2 decimals, formatted as shown (with the % at the end).

Examples

chance(3, 6) ➞ "4.63%"
// There is approximately 4.63% chance for rolling 6 with 3 dice.

chance(5, 20) ➞ "8.37%"

chance(2, 7) ➞ "16.67%"

Notes

N/A

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.