Tell us what’s happening:
Sorry, your code does not pass. Hang in there.
When the array has less than three of the same number, your getHighestDuplicates function should update the final radio option with , score = 0.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
function getHighestDuplicates(diceArray=Array.from(listOfAllDice)) {
const counts = {};
diceArray.forEach(die => {
counts[die] = (counts[die] || 0) + 1;
});
let maxCount = 0;
for (let key in counts) {
if (counts[key] > maxCount) {
maxCount = counts[key];
}
}
const totalSum = diceArray.reduce((sum, die) => sum + die, 0);
if (maxCount >= 4) {
updateRadioOption(1, totalSum);
} else if (maxCount >= 3) {
updateRadioOption(0, totalSum);
} else {
updateRadioOption(0, 0);
updateRadioOption(1, 0);
}
}
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
rollDice();
updateStats();
getHighestDuplicates;
}
});
// 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/126.0.0.0 Safari/537.36 Edg/126.0.0.0
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7