My code for this step appears to be working correctly, but it doesn’t pass. Is the solution evaluator bugged?
const getHighestDuplicates = nums => {
for (let i = 0; i < scoreInputs.length; i++) {
scoreInputs[i].disabled = true;
scoreSpans[i].textContent = "";
}
let repeats = {};
nums.forEach(num => {
repeats[num] = (repeats[num] || 0) + 1;
});
let highest = 0;
Object.keys(repeats).forEach(key => {
if (highest < repeats[key]) {
highest = repeats[key];
}
});
if (highest === 3) {
updateRadioOption(0, diceValuesArr.reduce((acc, num) => acc + num, 0));
} else if (highest >= 4) {
const sum = diceValuesArr.reduce((acc, el) => acc + el, 0);
updateRadioOption(0, sum);
updateRadioOption(1, sum);
}
updateRadioOption(5, 0);
return;
}
rollDiceBtn.addEventListener("click", () => {
if (rolls === 3) {
alert("You have made three rolls this round. Please select a score.");
} else {
rolls++;
rollDice();
updateStats();
getHighestDuplicates(diceValuesArr);
}
});
I have verified the sum is correct and that the Three of a Kind and Four of a Kind options are only active when appropriate. I think it maybe has to do with the forEach on my object keys? I know this isn’t the cleanest, but it should work.
This is my console output:
// running tests
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.
6. When the array has four of the same number, your getHighestDuplicates function should update the Four of a Kind radio option with , score = and the total sum of the dice.
7. When the array has four of the same number, your getHighestDuplicates function should also update the Three of a Kind radio option with , score = and the total sum of the dice.
// tests completed