Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

I have the correct code written in compliant with the user stories but I can’t seem to pass the test. I need help pointing out what it is I’m missing

Your code so far

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

/* file: styles.css */

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

const getHighestDuplicates = (arr) => {
  const counts = {};
  let highestCount = 0;

  for (const num of arr) {
    counts[num] = (counts[num] || 0) + 1;
  }

  for (const count of Object.values(counts)) {
    if (count >= 3 && count > highestCount) {
      highestCount = count;
    }
  }

  return highestCount;
};


rollDiceBtn.addEventListener("click", () => {
  if (rolls === 3) {
    alert("You have made three rolls this round. Please select a score.");
  } else {
    rolls++;
    rollDice();
    updateStats();
    
     const highestDuplicate = getHighestDuplicates(diceValuesArr);
    const total = diceValuesArr.reduce((sum, value) => sum + value, 0);

       updateRadioOption(5, 0);

    if (highestDuplicate >= 4) {
      updateRadioOption(3, total);
    }

    if (highestDuplicate >= 3) {
      updateRadioOption(2, total);
    }


  }
});

// 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/143.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

All of this code should be inside your getHighestDuplicates function. You should just be calling getHighestDuplicates within the rollDiceBtn event listener.

Uhm, where exactly do I put the code? because I’m still encountering difficulties in passing this stage

Please read my response again.

I did that, and I’m still getting the same response:

const getHighestDuplicates = (arr = diceValuesArr) => {
  const counts = {};
  let highestCount = 0;

  for (const num of arr) {
    counts[num] = (counts[num] || 0) + 1;
  }

  for (const count of Object.values(counts)) {
    if (count >= 3 && count > highestCount) {
      highestCount = count;
    }
  }

  const highestDuplicate = highestCount;
  const total = arr.reduce((sum, value) => sum + value, 0);

  updateRadioOption(5, 0);

  if (highestDuplicate >= 4) {
    updateRadioOption(3, total);
  }

  if (highestDuplicate >= 3) {
    updateRadioOption(2, total);
  }

  return highestDuplicate;
};

rollDiceBtn.addEventListener("click", () => {
  if (rolls === 3) {
    alert("You have made three rolls this round. Please select a score.");
  } else {
    rolls++;
    rollDice();
    updateStats();
    getHighestDuplicates(diceValuesArr);
  }
});



And this still displays:

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.
6. When the array has four of the same number, your getHighestDuplicates function should update the Four of a Kind radio option with , score = and the total sum of the dice.
7. When the array has four of the same number, your getHighestDuplicates function should also update the Three of a Kind radio option with , score = and the total sum of the dice.

I just figured out my error. It was in the array indexing - I applied the wrong array index for the duplicates. Thanks a lot.