Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

I keep getting the same message: “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.”
I have tried to look at different ways to change this, as well as looking at earlier questions, but nothing changes this notification. It does still work in the browser preview.

Your code so far

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

/* file: styles.css */

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

const getHighestDuplicates = (arr) => {
  const counts = {};

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

  let highestCount = 0;

  for(const num of arr) {
    const count = counts[num];
    if (count >= 3 && count > highestCount) {
      highestCount = count;
    } 
    if (count >= 4 && count > highestCount) {
      highestCount = count;
    }
  }

const sumOfAllDice = diceValuesArr.reduce((a, b) => a + b, 0);

  if (highestCount >= 4) {
    updateRadioOption(1, sumOfAllDice);
  } 
  if (highestCount >= 3) {
    updateRadioOption(0, sumOfAllDice);
  }
  else {
    updateRadioOption(5,0);
    };
};

  const resetRadioOption = () => {
    scoreInputs.forEach(input => {
      input.disabled = true;
      input.checked = false;
    });

  scoreSpans.forEach(span => {
    span.textContent = "";
  });
 };

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

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

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

Hello, try resetting the test page, just copy your code first.

You should call your reduce on the arr parameter, not diceValuesArr.

1 Like

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge.

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.