Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

i cant seem to get the final radio option to update when my getHighestDuplicates function encounters an array with less the 3 of the same number to “, score = 0” can anyone help me and explain where im gioing wrong

Your code so far

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

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

const getHighestDuplicates = array => {
  const duplicates = {};

  array.forEach(num => {
    duplicates[num] = (duplicates[num] || 0) + 1;
  });

  let maxCnt = 0;
  let maxDuplicates
  let sum = array.reduce((sum, value) => sum + value, 0)

  for (const [duplicates, cnt] of Object.entries(duplicates)) {
    if (cnt > maxCnt) {
      maxCnt = cnt;
      maxDuplicates = duplicates;
    }
  }
  for (const cnt in duplicates) {
    if (cnts[cnt] < 3) {
      updateRadioOption(5, 0);
      return;
    }
  }
  if (maxCnt > 3) {
    updateRadioOption(1, sum);
  } else if (maxCnt > 2) {
    updateRadioOption(0, sum);
  }
};


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; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

This call should be done without any logic around it. That is, just call this function all the time (every time the getHighestDuplicated is called, you should call this).

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