Review Algorithmic Thinking by Building a Dice Game - Step 7

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

arr.reduce((a, b) => a + b, 0). ---- since this is an implicit return statement, you need to place the return in a variable

arr += arr.sort((a, b) => a - b) —this is wrong concatenation. you need to create a ‘shallow copy’ then concatenate the sort()