Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

Hello guys.
Technically it works. But the test won’t let it pass. Spent so much time trying to understand what could be wrong. I don’t know what to do anymore. Do you have any clue?
Thanks a lot!

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

const getHighestDuplicates = (diceList) => {
  let arr = [0,0,0,0,0];
  let sum = 0;
  for(let i=0 ; i < 5 ; i++) {
    arr[diceList[i].textContent]++;
    sum+=Number(diceList[i].textContent);
  }
  arr.sort((a,b)=>b-a)
  if(arr[0]>=4) {updateRadioOption(1, sum);}
  if(arr[0]>=3) {updateRadioOption(0, sum);}
  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(listOfAllDice);
  }
});

// User Editable Region

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

Hi and welcome to the forum.

This question has many different posts already that you may want to look at for ideas.

To get you started though, please review the exercise requirement below:

create a getHighestDuplicates function which takes an array of numbers.

You have not done this yet because you are not passing in the dice number array. So start there and take a look at some of the posts about this step as well to complete your research.

Thank you so much!!
Sending the listOfAllDice was totally meaningless so I should have noticed this detail…

(for the other guys - I actually had another two mistakes of declaring the counter-arr with only 5 items instead of 6, and of not taking -1 of the dice value when using it as an index)

1 Like