---
id: 657e37e29b45c39a98482860
title: Step 86
challengeType: 0
dashedName: step-86
---
# --description--
If the user does not get a small or large straight, call the `updateRadioOption` function and pass in the numbers `5` and `0` for the arguments.
# --hints--
You should call the `updateRadioOption` function and pass in the numbers `5` and `0` for the arguments.
```js
assert.match(checkForStraights.toString(), /updateRadioOption\s*\(\s*5\s*,\s*0\s*\)\s*;?/);
```
# --seed--
## --seed-contents--
```html
Advanced Dice Game
Advanced Dice Game
Show rules
Rules
There are total of six rounds
You can only roll the dice three times per round
To start the game, roll the dice
Then, choose from one of the selected scores or roll the dice again
If you choose a selected score, then you will move to the next round
If you decline to choose a selected score, then you can roll the
dice again two more times
Points
Three of a kind: Sum of all five dice
Four of a kind: Sum of all five dice
Full house: Three of a kind and a pair - 25 points
Small straight: Four of the dice have consecutive values - 30 points
Large straight: All five dice have consecutive values - 40 points
Score history (Total score: 0 )
```
```css
*,
*::before,
*::after {
box-sizing: border-box;
margin: 0;
padding: 0;
}
:root {
--dark-grey: #1b1b32;
--light-grey: #f5f6f7;
--black: #000;
--white: #fff;
--grey: #3b3b4f;
--golden-yellow: #fecc4c;
--yellow: #ffcc4c;
--gold: #feac32;
--orange: #ffac33;
--dark-orange: #f89808;
}
body {
background-color: var(--dark-grey);
}
header {
color: var(--light-grey);
text-align: center;
}
h1 {
font-size: 2.5rem;
margin: 25px 0;
}
.rules-container {
display: none;
background-color: var(--light-grey);
color: var(--black);
width: 50%;
margin: 20px auto;
height: 300px;
border-radius: 10px;
overflow-y: scroll;
}
.rules-container ul {
list-style-type: none;
}
.points {
margin-top: 15px;
}
main {
background-color: var(--light-grey);
padding: 20px;
display: grid;
grid-template-columns: repeat(auto-fit, minmax(500px, 1fr));
gap: 1rem;
margin: auto;
justify-items: center;
width: 50%;
border-radius: 10px;
}
#dice {
display: flex;
justify-content: space-around;
margin-bottom: 15px;
}
.die {
width: 40px;
height: 40px;
text-align: center;
margin-right: 15px;
border: 4px solid var(--black);
padding: 10px;
}
.rounds-text {
text-align: center;
}
input[type="radio"]:disabled + label {
color: var(--grey);
}
#score-history {
margin-top: 15px;
text-align: center;
list-style-position: inside;
}
.btn {
cursor: pointer;
width: 200px;
margin: 10px 0 10px 0.5rem;
color: var(--black);
background-color: var(--gold);
background-image: linear-gradient(var(--golden-yellow), var(--orange));
border-color: var(--gold);
border-width: 3px;
}
.btn:hover:enabled {
background-image: linear-gradient(var(--yellow), var(--dark-orange));
}
@media (max-width: 992px) {
main {
width: 100%;
}
}
@media (max-width: 500px) {
.btn {
width: 120px;
}
}
```
```js
const listOfAllDice = document.querySelectorAll(".die");
const scoreInputs = document.querySelectorAll("#score-options input");
const scoreSpans = document.querySelectorAll("#score-options span");
const currentRoundText = document.getElementById("current-round");
const currentRoundRollsText = document.getElementById("current-round-rolls");
const totalScoreText = document.getElementById("total-score");
const scoreHistory = document.getElementById("score-history");
const rollDiceBtn = document.getElementById("roll-dice-btn");
const keepScoreBtn = document.getElementById("keep-score-btn");
const rulesContainer = document.querySelector(".rules-container");
const rulesBtn = document.getElementById("rules-btn");
let diceValuesArr = [];
let isModalShowing = false;
let score = 0;
let totalScore = 0;
let round = 1;
let rolls = 0;
const rollDice = () => {
diceValuesArr = [];
for (let i = 0; i < 5; i++) {
const randomDice = Math.floor(Math.random() * 6) + 1;
diceValuesArr.push(randomDice);
};
listOfAllDice.forEach((dice, index) => {
dice.textContent = diceValuesArr[index];
});
};
const updateStats = () => {
currentRoundRollsText.textContent = rolls;
currentRoundText.textContent = round;
};
const updateRadioOption = (optionNode, score) => {
scoreInputs[optionNode].disabled = false;
scoreInputs[optionNode].value = score;
scoreSpans[optionNode].textContent = `, score = ${score}`;
};
const updateScore = (selectedValue, achieved) => {
totalScore += parseInt(selectedValue);
totalScoreText.textContent = totalScore;
scoreHistory.innerHTML += `${achieved} : ${selectedValue} `;
};
const getHighestDuplicates = (arr) => {
const counts = {};
for (const num of arr) {
if (counts[num]) {
counts[num]++;
} else {
counts[num] = 1;
}
}
let highestCount = 0;
for (const num of arr) {
const count = counts[num];
if (count >= 3 && count > highestCount) {
highestCount = count;
}
if (count >= 4 && count > highestCount) {
highestCount = count;
}
}
const sumOfAllDice = diceValuesArr.reduce((a, b) => a + b, 0);
if (highestCount >= 4) {
updateRadioOption(1, sumOfAllDice);
}
if (highestCount >= 3) {
updateRadioOption(0, sumOfAllDice);
}
updateRadioOption(5, 0);
};
const detectFullHouse = (arr) => {
const counts = {};
for (const num of arr) {
counts[num] = counts[num] ? counts[num] + 1 : 1;
}
const hasThreeOfAKind = Object.values(counts).includes(3);
const hasPair = Object.values(counts).includes(2);
if (hasThreeOfAKind && hasPair) {
updateRadioOption(2, 25);
}
updateRadioOption(5, 0);
};
const checkForStraights = (arr) => {
const sortedNumbersArr = arr.sort((a, b) => a - b);
const uniqueNumbersArr = [...new Set(sortedNumbersArr)];
const uniqueNumbersStr = uniqueNumbersArr.join("");
const smallStraightsArr = ["1234", "2345", "3456"];
const largeStraightsArr = ["12345", "23456"];
if (smallStraightsArr.some(straight => uniqueNumbersStr.includes(straight))) {
updateRadioOption(3, 30);
}
if (largeStraightsArr.includes(uniqueNumbersStr)) {
updateRadioOption(4, 40);
}
--fcc-editable-region--
--fcc-editable-region--
};
const resetRadioOption = () => {
scoreInputs.forEach((input) => {
input.disabled = true;
input.checked = false;
});
scoreSpans.forEach((span) => {
span.textContent = "";
});
};
const resetGame = () => {
diceValuesArr = [0, 0, 0, 0, 0];
score = 0;
totalScore = 0;
round = 1;
rolls = 0;
listOfAllDice.forEach((dice, index) => {
dice.textContent = diceValuesArr[index];
});
totalScoreText.textContent = totalScore;
scoreHistory.innerHTML = "";
currentRoundRollsText.textContent = rolls;
currentRoundText.textContent = round;
resetRadioOption();
};
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
resetRadioOption();
rollDice();
updateStats();
getHighestDuplicates(diceValuesArr);
detectFullHouse(diceValuesArr);
}
});
rulesBtn.addEventListener("click", () => {
isModalShowing = !isModalShowing;
if (isModalShowing) {
rulesBtn.textContent = "Hide Rules";
rulesContainer.style.display = "block";
} else {
rulesBtn.textContent = "Show Rules";
rulesContainer.style.display = "none";
}
});
keepScoreBtn.addEventListener("click", () => {
let selectedValue;
let achieved;
for (const radioButton of scoreInputs) {
if (radioButton.checked) {
selectedValue = radioButton.value;
achieved = radioButton.id;
break;
}
}
if (selectedValue) {
rolls = 0;
round++;
updateStats();
resetRadioOption();
updateScore(selectedValue, achieved);
if (round > 6) {
setTimeout(() => {
alert(`Game Over! Your total score is ${totalScore}`);
resetGame();
}, 500);
}
} else {
alert("Please select an option or roll the dice");
}
});
```