Tell us what’s happening:
should have a function called getHighestDuplicates. The code already has it. but still not passing the test case. I am not able to find the error .please help me to find the error.
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
const getHighestDuplicates = (dice) => {
const counts = dice.reduce((acc, num) => {
acc[num] = (acc[num] || 0) + 1;
return acc;
}, {});
const hasFourOfAKind = Object.values(counts).some(count => count >= 4);
const hasThreeOfAKind = Object.values(counts).some(count => count >= 3);
if (hasFourOfAKind) {
return { type: 'fourOfAKind', sum: dice.reduce((total, value) => total + value, 0) };
}
if (hasThreeOfAKind) {
return { type: 'threeOfAKind', sum: dice.reduce((total, value) => total + value, 0) };
}
return null;
};
const updateRadioOption = (optionName, score) => {
const optionElement = document.querySelector(`input[name="scoreOption"][value="${optionName}"]`);
if (optionElement) {
optionElement.nextElementSibling.textContent = `${optionName} (${score})`;
}
};
// Assuming rollDiceBtn is already defined in your HTML
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
return;
}
rolls++;
rollDice(); // Assume this updates the dice array
updateStats(); // Assume this updates the UI with the new dice values
const dice = getCurrentDiceValues(); // This should return an array of dice values
const result = getHighestDuplicates(dice);
if (result) {
updateRadioOption(result.type === 'fourOfAKind' ? 'Four of a Kind' : 'Three of a Kind', result.sum);
}
updateRadioOption('Final Option', 0);
});
// User Editable Region
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7