Tell us what’s happening:
Please help as I don’t know what I’m doing wrong here. It keeps saying I need to update the four of a kind radio option with , score = and the sum of the dice. I feel like I already did that though.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const getHighestDuplicates = (diceValuesArr) => {
const counts = {};
for (let i = 0; i < diceValuesArr.length; i++) {
const num = diceValuesArr[i];
if (counts[num]) {
counts[num]++;
} else {
counts[num] = 1;
}
}
const totalScore = diceValuesArr.reduce((acc, val) => acc + val, 0);
for (const num in counts) {
if (counts[num] <= 2) {
updateRadioOption(5, score);
} else if (counts[num] >= 3) {
updateRadioOption(0, totalScore);
updateRadioOption(5,score);
break;
} else if (counts[num] >= 4) {
updateRadioOption(0, totalScore);
updateRadioOption(1, totalScore);
updateRadioOption(5,score);
break;
}
}
console.log(counts);
};
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
rollDice();
updateStats();
getHighestDuplicates(diceValuesArr);
}
});
// 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 Edg/131.0.0.0
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7