Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

When the array has less than three of the same number, your getHighestDuplicates function should update the final radio option with , score = 0.

Your code so far

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

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


const getHighestDuplicates = (diceValuesArr) => {
  const duplicates = {};
  let maxCount = 0;

  for (const value of diceValuesArr) {
    duplicates[value] = (duplicates[value] || 0) + 1;
    if (duplicates[value] > maxCount) {
      maxCount = duplicates[value];
    }
  }

  return { maxCount };
}

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

    const { maxCount } = getHighestDuplicates(diceValuesArr);
    const totalSum = diceValuesArr.reduce((sum, value) => sum + value, 0);
  if (maxCount >= 4) {
        updateRadioOption(1, totalSum); 
      } else if (maxCount >= 3) {
        updateRadioOption(0, totalSum); 
      }
      else{
      updateRadioOption(5, 0); 
      }
}  
});

// User Editable Region
/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) 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

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!

1 Like

My code is still not passing.
I have checked the block of code over and over again.

Hi there!

Within the rollDiceBtn event callback, you only need to call the getHighestDuplicate` function with an argument. The other all logic should goes within that function body.

Thank you for the responses.

1 Like