Tell us what’s happening:
What is wrong with my code? I have 2 issues: 4. 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.
5. When the array has three of the same number, your getHighestDuplicates function should not update the Four of a Kind radio option.
I think it is here: //check if Four of a Kind
if (Object.values(counts).some(count => count === 4)) {
updateRadioOption(0, total);
updateRadioOption(1, total);
}
//check if Three of a Kind
else if (Object.values(counts).some(count => count === 3)) {
updateRadioOption(1, total);
}
// if nothing compares
else {
updateRadioOption(5, 0);
}
}
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
function getHighestDuplicates(diceValuesArr) {
const counts = {};
let total = 0;
diceValuesArr.forEach(ele => {
if (counts[ele]) {
counts[ele] += 1;
total += ele;
} else {
counts[ele] = 1;
total += ele;
}
});
//check if Four of a Kind
if (Object.values(counts).some(count => count === 4)) {
updateRadioOption(0, total);
updateRadioOption(1, total);
}
//check if Three of a Kind
else if (Object.values(counts).some(count => count === 3)) {
updateRadioOption(1, total);
}
// if nothing compares
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(diceValuesArr);
}
});
// 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/131.0.0.0 Safari/537.36 Edg/131.0.0.0
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7