Tell us what’s happening:
I get “Uncaught TypeError: arr.reduce is not a function” in the console and I’m not sure how else to write that the arr param is an array of numbers. I am also unsure why this code doesn’t pass and what I’m missing.
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
const getHighestDuplicates = (arr) => {
function sum(arr){
arr.reduce((a, b) => a + b, 0)
}
arr += arr.sort((a, b) => a - b)
for (let i = 0; arr.length > i; i++){
if (arr[i] === arr[i++] === arr[i+2] !== arr[i+3] || arr[i] !== arr[i++] === arr[i+2] === arr[i+3] !== arr[i+4] || arr[i++] !== arr[i+2] === arr[i+3] === arr[i+4]){
updateRadioOption(0, sum(...arr));
}
else if (arr[i] === arr[i++] === arr[i+2] === arr[i+3] || arr[i++] === arr[i+2] === arr[i+3] === arr[i+4]){
updateRadioOption(1, sum(...arr))
}
else if (arr[i] === arr[i++] !== arr[i+2] !== arr[i+3]){
updateRadioOption(5, 0)
}
}}
rollDice()
console.log(getHighestDuplicates(diceValuesArr))
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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 7