Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

From what I can see my getHighestDuplicates function is working properly, but it is not passing. Here is the feedback I get:

“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.”

(When I get 3 of a kind everything seemingly updates as needed)

**edit: I did find one bug. If I get a 3 of a kind on the first or second roll, and then not on the next roll, the 3 of a kind option still stays enabled.

Your code so far

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

/* file: styles.css */

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

const getHighestDuplicates = (array) => {
  const counts = {};
  const score = diceValuesArr.reduce((acc, el) => acc + el, 0);
  array.forEach((el) => {
    counts[el] = (counts[el] || 0) + 1;
    if (counts[el] >= 4) {
    updateRadioOption(1, score);
    updateRadioOption(0, score);
    updateRadioOption(5, 0);
    } else {
      if (counts[el] >= 3) {
      updateRadioOption(0, score);
      updateRadioOption(5, 0);
      } 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(diceValuesArr)
  }
});

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

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

Hi @dipittman

Try using the parameter passed to the function, instead of directly accessing the diceValuesArr array.

This code will pass, however you could tidy up the code.
See if you can find a way of not repeating updateRadioOption(5, 0);

Happy coding

Yes, changing the direct diceValuesArr reference to array made it pass. Still don’t quite understand why though.

And then I also saw the more efficient way of updating the None option (just not using an else statement.

Thank you for your help!

1 Like