Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

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.

Your code so far

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

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

const getHighestDuplicates = (arr) => {
  
  arr.sort((a, b) => a - b);
  
  let maxElement = arr[0];
  let maxSumma = 0;
  let arr2 = [];
  let summElement = 0;
  for(let element of arr){
    summElement += element;
    if(element == maxElement){
      arr2.push(element);
    } else{
      if(maxSumma < arr2.length){
        maxSumma = arr2.length;
      }
      arr2 = [];
    }
  }

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


rollDiceBtn.addEventListener("click", () => {
  if (rolls === 30) {
    alert("You have made three rolls this round. Please select a score.");
  } else {
    rolls++;
    rollDice();
    updateStats();
    getHighestDuplicates(diceValuesArr);
  }
});

// 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/130.0.0.0 YaBrowser/24.12.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

Please Tell us what’s happening in your own words.

Learning to describe problems is hard, but it is an important part of learning how to code.

Also, the more you say, the more we can help!