Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

I get an error that says “When the array has three of the same number, your getHighestDuplicates function should update the Three of a Kind radio option with , score = and the total sum of the dice.”. It looks like I am checking that already with larger or equal. I don’t know what to do here. I was using diceValuesArr directly instead of numbers array. I fixed that but nothing changed.

Your code so far

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

/* file: styles.css */

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

const getHighestDuplicates = (numbers) => {
  const count = {};
  const sum = numbers.reduce((a, b) => a + b, 0);
  numbers.forEach(num => {
    count[num] = (count[num] || 0) + 1;
    if(count[num]) {
      count[num]++;
    } else {
      count[num] = 1;
    }
  });
  Object.keys(count).forEach(num => {
    if (count[num] >= 4) {
      updateRadioOption(1, sum);
      updateRadioOption(5, 0);
    } else if (count[num] >= 3) {
      updateRadioOption(0, sum);
      updateRadioOption(5, 0);
    }
  });

  if (Math.max(...Object.values(count)) < 3) {
    updateRadioOption(scoreSpans.length - 1, 0);
  }
  
}

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; rv:132.0) Gecko/20100101 Firefox/132.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

I have also checked the console and it says

// running tests
5. When the array has three of the same number, your getHighestDuplicates function should not update the Four of a Kind radio option.
// tests completed

It seems like it doesn’t do that tho, it only updates the three of a kind option and the last option?

Note: I added updateRadioOption(0, sum); to the first if statement.

I have fixed the problem!