Tell us what’s happening:
const getHighestDuplicates = (arr) => {
let countObj = {}
let totalScore = 0;
let maxCount = 0;
let maxDuplicate = null;
arr.forEach((num) => {
countObj[num] = (countObj[num] || 0) + 1;
totalScore += num;
});
if (countObj[num] > maxCount) {
maxCount = countObj[num]; // value
maxDuplicate = num // key
}
if (maxCount < 3) {
updateRadioOption(5, 0)
} else if (maxCount === 3) {
updateRadioOption(0, totalScore)
} else if (maxCount === 4) {
updateRad
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const getHighestDuplicates = (arr) => {
let countObj = {}
let totalScore = 0;
let maxCount = 0;
let maxDuplicate = null;
arr.forEach((num) => {
countObj[num] = (countObj[num] || 0) + 1;
totalScore += num;
});
if (countObj[num] > maxCount) {
maxCount = countObj[num]; // value
maxDuplicate = num // key
}
if (maxCount < 3) {
updateRadioOption(5, 0)
} else if (maxCount === 3) {
updateRadioOption(0, totalScore)
} else if (maxCount === 4) {
updateRadioOption(1, totalScore)
}
};
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
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7