Tell us what’s happening:
Day 3 of trying to figure this out. I think my code is doing what’s asked but it’s not passing. my radio buttons seem to be updating correctly and disabling with new rolls (keeping radio buttons active did not pass either). I’ve tried updating the “none of the above” option in its own function, in the event listener, and in the getHighestDuplicates function both in the if else statement testing array.length and just updating it at the beginning of the function.
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
const resetInput = () => {
scoreInputs[0].disabled = true;
scoreSpans[0].textContent = ``;
scoreInputs[1].disabled = true;
scoreSpans[1].textContent = ``;
scoreInputs[2].disabled = true;
scoreSpans[2].textContent = ``;
scoreInputs[3].disabled = true;
scoreSpans[3].textContent = ``;
scoreInputs[4].disabled = true;
scoreSpans[4].textContent = ``;
}
const getHighestDuplicates = () => {
let fourOfaKind = [];
let threeOfaKind = [];
let match = [];
const sorted = diceValuesArr.sort();
const diceTotal = diceValuesArr.reduce((a, b) => a + b, 0);
for(let i = 0; i < sorted.length; i++) {
if(sorted[i] === sorted[i + 1] && sorted[i] === sorted[i + 2] && sorted[i] === sorted[i + 3]) {
fourOfaKind.push(sorted[i]);
}else if(sorted[i] === sorted[i + 1] && sorted[i] === sorted[i + 2] && sorted[i] !== sorted[i - 1]) {
threeOfaKind.push(sorted[i]);
}else if(sorted[i] === sorted[i + 1] && sorted[i] !== sorted[i + 2] && sorted[i] !== sorted[i - 1]) {
match.push(sorted[i]);
}
}
if(fourOfaKind.length === 1) {
updateRadioOption(1, diceTotal);
updateRadioOption(0, diceTotal);
return;
}else if(threeOfaKind.length === 1) {
updateRadioOption(0, diceTotal);
return;
}
}
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
rollDice();
resetInput();
updateRadioOption(5, 0);
getHighestDuplicates();
}
});
// User Editable Region
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7