the code works but i am still mising 3 things, 4, 6, and 7
i got the score when i roll, but what to do for my code to pass?
- When the array has three of the same number, your getHighestDuplicates function should update the Three of a Kind radio option with , score = and the total sum of the dice.
const getHighestDuplicates = () => {
const diceCounts = {};
let totalSum = 0;
// Count occurrences of each die value
diceValuesArr.forEach(value => {
diceCounts[value] = (diceCounts[value] || 0) + 1;
totalSum += value;
});
let fourOfAKind = false;
let threeOfAKind = false;
let value = 0;
let threeOfAKindSum = 0;
// Check for Four of a Kind or Three of a Kind
for (const [key, count] of Object.entries(diceCounts)) {
const dieValue = parseInt(key);
if (count >= 4) {
fourOfAKind = true;
value = dieValue;
totalSum = value * 4;
break;
} else if (count === 3) {
threeOfAKind = true;
value = dieValue;
threeOfAKindSum = value * 3;
}
}
if (fourOfAKind) {
updateRadioOption(1, totalSum);
} else if (threeOfAKind) {
updateRadioOption(0, threeOfAKindSum);
} else {
updateRadioOption(5, 0);
}
};
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
rollDice();
updateStats();
getHighestDuplicates();
}
});