Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

Not sure what to do here/if I’m supposed to add a lot more

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.

Your code so far

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

/* file: styles.css */

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

const getHighestDuplicates = ([a,b,c,d,e]) => {
  if ("three-of-a-kind"){
    updateRadioOption(0, (a+b+c+d+e))
  }
  else if ("four-of-a-kind"){
    updateRadioOption(1, (a+b+c+d+e))
  }
  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()
  }
});

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) 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

You might be on the right track for the last part of this. One thing I noticed is the test thinks you are trying to descructure but there isnt anything to do this. You should remove [] and put some param there. Good luck

Tell me what’s confusing you and what needs clarified.

Instead of the blank array I put diceValuesArr as the getHighestDuplicates param, and put the sum of the array as the score parameter in the updateRadioOption function. For the index parameter in updateRadioOption, I put 0 (three of a kind) and 1 (four of a kind). Not sure what I would put for index in the else category other than 5 (none of the above option) and 0 for score.

More specifically, my question is: is this step of the project instructing me to write the code for identifying 3 and 4 of a kind in the subset of numbers (instead of if(“three-of-a-kind”))?

And for the else case, what would the index param for updateRadioOption() be if not the index 5 of radio options?

const getHighestDuplicates = diceValuesArr => {
  if ("three-of-a-kind"){
        updateRadioOption(0, diceValuesArr.reduce((a, b) => a + b))
  }
  else if ("four-of-a-kind"){
        updateRadioOption(1, diceValuesArr.reduce((a, b) => a + b))
  }
  else{
        updateRadioOption()
  }
}

This is the idea I have for checking for 3 and 4 of a kind

const getHighestDuplicates = diceValuesArr => {
  diceValuesArr = diceValuesArr.sort(nums)
  for (let i = 0; diceValuesArr.length > i; i++){
    if (diceValuesArr[i] === diceValuesArr[i++] === diceValuesArr[i+2] !== diceValuesArr[i+3]){
       updateRadioOption(0, diceValuesArr.reduce((a, b) => a + b))
    }
    else if (diceValuesArr[i] === diceValuesArr[i++] === diceValuesArr[i+2] === diceValuesArr[i+3]){
      updateRadioOption(1, diceValuesArr.reduce((a, b) => a + b))
    }
  else if (diceValuesArr[i] === diceValuesArr[i++] !== diceValuesArr[i+2] || diceValuesArr[i] !== diceValuesArr[i++]){
    updateRadioOption(5, 0)
  }
  }}