Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

I keep getting the “hint”:
When the array has less than three of the same number, your getHighestDuplicates function should update the final radio option with , score = 0.
it shows up on the preview as such, and the “four of a kind” and “three of a kind” are also responsive. I noticed that if a four or three of a kind come up on the first or second roll, my radio options do not reset for the next roll (four or three of a kind option remain “active” with the score.) Is that my issue?

Your code so far

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

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


const getHighestDuplicates = arr => {
  const sum = diceValuesArr.reduce((a, b) => a + b, 0);
  const numCount = {};
  for (const i of diceValuesArr) {
    if (numCount[i]) {
      numCount[i]++
    } else {
      numCount[i] = 1
    }
  };
  for (let i in numCount) {
    if (numCount[i] >= 4) {
      updateRadioOption(1, sum)
      } else if (numCount[i] >= 3) {
      updateRadioOption(0, sum)
      } else if (numCount[i] < 3) {
      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();
  }
})

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

getHighestDuplicates() takes an arr parameter, but you are not passing one in when you call your function.

Regardless of the outcome, the final option should be updated with a score of 0 .

Also, take another look at this instruction, and think some more about your 4-of-a-kind logic.

how did I miss that… been staring at this stuff for too long…
so I updated my ‘for’ statement to the following:

    if (numCount[i] >= 4) {
      updateRadioOption(1, sum);
      updateRadioOption(5, 0)
      } else if (numCount[i] >= 3) {
      updateRadioOption(0, sum);
      updateRadioOption(5, 0)
      } else if (numCount[i] < 3) {
      updateRadioOption(5, 0)
    }
  }
};```
and added my array to my function call:
```rollDiceBtn.addEventListener("click", () => {
  if (rolls === 3) {
    alert("You have made three rolls this round. Please select a score.");
  } else {
    rolls++;
    rollDice();
    updateStats();
    getHighestDuplicates(diceValuesArr);
  }
})```
but I'm still getting the same hint when I check the code

If the last radio option should be enabled regardless of the outcome, maybe it shouldn’t be subject to a conditional.

Good progress so far.

Please give more thought to your 4-of-a-kind logic, though. That needs work.

Good luck!

thank you F, will do.

Got it. it was what you were saying AND it wanted me to pass diceValuesArr to the arrow function directly instead of just “arr”. thank you for your time, that was driving me nuts

I tried updating the final radio option outside of the conditionals, but it was before I changed my parameter, so I’m not sure if the step will accept that. I had just spelled everything out in each conditional before thinking to try the new parameter and that worked for me. hope this helps someone else who’s about to throw their laptop out the window :laughing:

Glad to hear you’re making progress! Please share your latest code updates if you still need help.

I’m good to go, on to step 8 now. thanks again!