Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

please help solving this; direct me please…
function getHighestDuplicates(dice) {
const counts = {};
dice.forEach(num => {
counts[num] = (counts[num] || 0) + 1;
});

const totalScore = dice.reduce((acc, num) => acc + num, 0);

if (counts >= 4) {
updateRadioOption(0, totalScore);
} else if (counts >= 3) {
updateRadioOption(1 , totalScore);
} else {
updateRadioOption(5 , 0);
}
}

Your code so far

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

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

function getHighestDuplicates(dice) {
    const counts = {};
    dice.forEach(num => {
        counts[num] = (counts[num] || 0) + 1;
    });

    const totalScore = dice.reduce((acc, num) => acc + num, 0);


  if (counts >= 4) {
        updateRadioOption(0, totalScore);
    } else if (counts >= 3) {
        updateRadioOption(1 , totalScore);
    } 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(dice);
    console.log(counts)
  }
});

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

hello and welcome to fcc forum :slight_smile:

  • where do you suspect that its not going your expected way?

happy coding :slight_smile:

i have a problem on that if conditions
i cant see the way of getting the times numbers have been seen

did you see any error in console when you are doing this? cause “counts” is defined as an “object” earlier in scope!!

happy coding :slight_smile: