Tell us what’s happening:
I think i may not have imputed the right array parameter here:
let sum0fScores = arr.reduce((a,b) => a + b, 0);
which was the parameter I inputted for the getHighestDuplicates function. consoles keep returning; cannot read properties of undefined (reading, ‘reduce’). Above i tried to use the param as the list of dice scores value, thus, to sum them up using the reduce method.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const getHighestDuplicates = (arr) => {
const counts = {};
let sum0fScores = arr.reduce((a,b) => a + b, 0);
arr.forEach(score => {
counts[score] = (counts[score] || 0) +1;
})
let fourOfAKind = false;
let threeOfAKind = false;
for (let score in counts) {
if (counts[score] >= 4) {
fourOfAKind = true;
if(fourOfAKind) {updateRadioOption(0, score = sum0fScores);}
}
else if (counts[score] >= 3) {
threeOfAKind = true;
if(threeOfAKind) {
updateRadioOption(1, score = sum0fScores);}
}
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();
}
});
// 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/128.0.0.0 Safari/537.36 Edg/128.0.0.0
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7