Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

I’m getting these errors:
When the array has three of the same number, your getHighestDuplicates function should update the Three of a Kind radio option with , score = and the total sum of the dice.
When the array has four of the same number, your getHighestDuplicates function should update the Four of a Kind radio option with , score = and the total sum of the dice.
When the array has four of the same number, your getHighestDuplicates function should also update the Three of a Kind radio option with , score = and the total sum of the dice.

const getHighestDuplicates = (arr) => {
  const counts = {};

  for (const num of arr) {
  if (counts[num]) {
    counts[num]++
    } else {
    counts[num] = 1
    }
  }
  let highestCount = 0;
  
  
  for (const num of arr) {
    const count = counts[num];
    if (count >= 3 && count > highestCount) {
      highestCount = count
    }
    if (count >= 4 && count > highestCount) {
      highestCount = count
    }
  }

const sumOfAllDice = diceValuesArr.reduce((a, b) => a + b, 0);

if (highestCount >= 4) {
  updateRadioOption(1, sumOfAllDice);
}

if (highestCount >= 3) {
  updateRadioOption(0, sumOfAllDice);
}

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(diceValuesArr);
  }
});

Please talk about how you are stuck fixing this error message. Also, please post a link to the Step. Thanks

I don’t understand why im getting that error message.

this is the step:

Step 7

If you roll the dice and get a "Three of a kind" or "Four of a kind", then you can get a score totalling the sum of all five dice values. To calculate this, create a getHighestDuplicates function which takes an array of numbers. The function will need to count how many times each number is found in the array.

If a number appears four or more times, you will need to update the Four of a Kind option with your updateRadioOption function. If a number appears three or more times, you will need to update the Three of a Kind option. In both cases, the score value should be the sum of all five dice.

If neither of those are true, the final option should be updated with a score of 0. Make sure to call your getHighestDuplicates when the dice are rolled.

Can you try talking about how you are stuck instead of copy-pasting the instructions please? What have you tried to understand why your code isn’t passing?

Here you wrote something that looks really close to the particular solution the person who wrote the Step was using personally. Neat since there’s literally millions of ways to approach this!

But I don’t understand what this code is for? That doesn’t seem to be part of this step?

my issue is, i don’t actually know which part of my code is incorrect. I don’t understand which part the error is referring to.

i think it’s referring to this part:

if (highestCount >= 4) {
  updateRadioOption(1, sumOfAllDice);
}

if (highestCount >= 3) {
  updateRadioOption(0, sumOfAllDice);
}

updateRadioOption(5, 0);
}

but i think i’ve done that correctly

And you haven’t tried anything in particular to try to figure out what’s wrong with your code? I would try to test it if I was you

I am stuck on the same part of this step with the same error. I am also not sure what the issue is. my code is:

    if(highestCount >= 4){
        updateRadioOption(1, `, score = ${score}`)
    }
    if(highestCount >= 3){
      updateRadioOption(0, `, score = ${score}`);
    }
    updateRadioOption(5, 0)

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.