Tell us what’s happening:
ERROR MESSAGE: Sorry, your code does not pass. Keep trying.
When a full house is rolled, your detectFullHouse function should enable the third radio button, set its value to 25, and set the third span to display the text , score = 25.
The issue lies in the implementation of the detectFullHouse function and how it interacts with the radio button and span elements.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const detectFullHouse = (arr) => {
const counts = {};
// Count the occurrences of each number
for (const num of arr) {
counts[num] = counts[num] ? counts[num] + 1 : 1;
}
const values = Object.values(counts);
const hasThreeOfAKind = values.includes(3);
const hasPair = values.includes(2);
// If a full house (three of one number, two of another) is rolled
if (hasThreeOfAKind && hasPair) {
// Enable third radio button, set value to 25
scoreInputs[2].disabled = false;
scoreInputs[2].value = 25;
// Set text to ", score = 25"
scoreSpans[2].textContent = `, score = 25`;
} else {
// Reset third radio button and span
scoreInputs[2].disabled = false;
scoreInputs[2].value = 0;
scoreSpans[2].textContent = `, score = 0`;
}
// Always reset the last radio button to score = 0
scoreInputs[5].disabled = false;
scoreInputs[5].value = 0;
scoreSpans[5].textContent = `, score = 0`;
};
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
resetRadioOptions();
rollDice();
updateStats();
getHighestDuplicates(diceValuesArr);
detectFullHouse(diceValuesArr); // Call detectFullHouse after rolling the dice
}
});
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 13