Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

I am just stuck, i can see the code working and updating the preview correctly, or at least i believe correctly. i have tried logging everything to the console to see what is happening, and i have looked through all the errors and just cant id what im doing wrong.

Your code so far

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

/* file: styles.css */

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

function getHighestDuplicates (numArr) {
  const counts = {};
  let rollScore = numArr.reduce((partialSum, a) => partialSum + a, 0);

  for (const num of numArr) {
    counts[num] = counts[num] ? counts[num] + 1 : 1;
  };

  for (let count in counts) {
    
    if(counts[count] >= 4) {
      updateRadioOption(1, rollScore);
      updateRadioOption(0, rollScore);
      return;
    } else if(counts[count] === 3) {
      updateRadioOption(0, rollScore);
      return;
    } else{
      updateRadioOption(5, 0);
      return;
    };
  };
};

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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

i know it is not clear from the instructions but you need to update the last radio button all the time (not just when there are no duplicates)

hmm, i added
updateRadioOption(5, 0);
to both the =3 and >=4 options and still no joy, ill keep trying though

I figured it out, my issue was with the return statement being present i the loop, therefore exiting out of the loop.

1 Like

can you explain how you figured it out