Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

I think I got it? It says that I don’t have any of the asked steps. But it does exactly what is asked. Can someone look at it and tell me what needs to be changed?

Your code so far

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

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

//counts what item appears the most
const getHighestDuplicates = () => {
  let count = diceValuesArr.reduce((count, curr) => {
    if (count[curr]){
      count[curr] += 1;
    } else {
      count[curr] = 1;
    }
    return count;
  }, {});

//returns how many time the most appearing item appears
  let maxCount = 0;

  for (let item in count) {
    if (count[item] > maxCount) {
      maxCount = count[item];
    }

//calculates the sum of all dice
    const sumOfAllDice = diceValuesArr.reduce((total, rest) => total + rest, 0);

    if (maxCount >= 3){
      updateRadioOption(0, sumOfAllDice);
    }
    if (maxCount >= 4){
      updateRadioOption(1, sumOfAllDice);
    } if (maxCount < 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; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

If there’s four matches , both four of a kind and three of a kind need to be updated.

1 Like

Thanks I changed it, but it didn’t let me past the test unfortunatily. It says:
// running tests When the array has less than three of the same number, your

getHighestDuplicates

function should update the final radio option with

, score = 0

. 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. // tests completed

What did you change?

Please share your updated code

1 Like

This is my code now. I didn’t leave the changed code, because it’s already taken care of with using >= instead of = by if (maxCount >= 3) (referring back to the user a2937)
Even when changed i dont’t pass… But for my feeling my code does everything it supposed to do in this step.

//counts what item appears the most
const getHighestDuplicates = () => {
  let count = diceValuesArr.reduce((count, curr) => {
    if (count[curr]){
      count[curr] += 1;
    } else {
      count[curr] = 1;
    }
    return count;
  }, {});

//returns how many time the most appearing item appears
  let maxCount = 0;

  for (let item in count) {
    if (count[item] > maxCount) {
      maxCount = count[item];
    }

//calculates the sum of all dice
    const sumOfAllDice = diceValuesArr.reduce((total, rest) => total + rest, 0);

    if (maxCount >= 3){
      updateRadioOption(0, sumOfAllDice);
    }
    if (maxCount >= 4){
        updateRadioOption(0, sumOfAllDice);
        
    } if (maxCount < 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();
  }
});```

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.