Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

I cannot get my code to update the radio options correctly. The combination checker seems to work fine, but if in different dice rolls the results changes the old radio option stays enabled. I think that’t the key of the issue, the radio button should be disabled if the dice changes between rolls in the same round

Your code so far

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

/* file: styles.css */

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

const getHighestDuplicates = (array) => {
  const counts = {};
  let sumOfDice = 0;
  array = diceValuesArr
  array.forEach(x => {
  counts[x] = (counts[x] || 0) + 1;
  });
  sumOfDice = array.reduce((acc, curr) => {
        return acc + curr;
      }, 0);
  let flagThree = Array.from(Object.values(counts)).some((x) => x >= 3);
  let flagFour = Array.from(Object.values(counts)).some((x) => x >= 4);
  if (flagThree && !flagFour) {
    updateRadioOption(0, sumOfDice)
  }
  if (flagFour && !flagThree) {
    updateRadioOption(1, sumOfDice)
  }
  if (!flagFour && !flagThree) {
    updateRadioOption(5, 0)
  }
}

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

// 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 Edg/126.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

I haven’t tried this project but the first thing i notice that you should look into is that this function call is not passing in an array of numbers.
The instructions said: To calculate this, create a getHighestDuplicates function which takes an array of numbers.

So I would start there.

Thank you very much, it was just this simple. I was focusing on the loops structure and I didn’t realized how I was not using the parameter correctly.
Thank you!

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.