diff --git a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657e0c2c6a9d37705146f34d.md b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657e0c2c6a9d37705146f34d.md index a7949dc5d04..866420a8a2f 100644 --- a/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657e0c2c6a9d37705146f34d.md +++ b/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/review-algorithmic-thinking-by-building-a-dice-game/657e0c2c6a9d37705146f34d.md @@ -45,19 +45,24 @@ assert.strictEqual(scoreSpans[5].innerText, ", score = 0"); You should call your `detectFullHouse` function when your `rollDiceBtn` is clicked. ```js -const counts = (arr) => arr.reduce((counts, num) => {counts[num] = ++counts[num] || 1; return counts}, {}); -const isFullHouse = (arr) => arr.includes(3) && arr.includes(2) && arr.length === 2; -// Absurdly high, but will either timeout or bail early when assertion runs. -for (let i = 0; i < 100_000; i++) { - rolls = 0; +// Temporarily modifies Math.random to guarantee full house. +const origMathRandom = Math.random +const myMathRandom = (() => { + let i = 0; + const values = [0, 0, 0, 1 / 6 + 0.000001, 1 / 6 + 0.000001]; + return () => values[i++ % 5]; +})(); + +Math.random = myMathRandom; +try { rollDiceBtn.click(); - if (isFullHouse(diceValuesArr)) { - assert.isFalse(scoreInputs[2].disabled); - assert.strictEqual(scoreInputs[2].value, "25"); - assert.strictEqual(scoreSpans[2].innerText, ", score = 25"); - break; - } +} finally { + Math.random = origMathRandom; } + +assert.isFalse(scoreInputs[2].disabled); +assert.strictEqual(scoreInputs[2].value, "25"); +assert.strictEqual(scoreSpans[2].innerText, ", score = 25"); ``` # --seed--