Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

It seems like there’s an issue with tests cause I’ve tested this many times, but I could be wrong. My getHighestDuplicates() code goes through the diceValuesArr and increments each value’s corresponding index in the numOrder array. Ex. diceValuesArr = [1, 2, 6, 5, 6] results in a [1, 1, 0, 0, 1, 2]. After this numOrder array is created, two if-statements determine if any of the numOrder indexes contain either a 3 or a value greater than 4. Then the corresponding radio option text is updated. Any help would be much appreciated :slight_smile:

Here’s my code:

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

const getHighestDuplicates = ()=>{
  updateRadioOption(5, 0)

  const numOrder = [0, 0, 0, 0, 0, 0]
  diceValuesArr.forEach((el)=> numOrder[el-1]++)
  const sum = diceValuesArr.reduce((acc, el) => acc + el, 0);
  if(numOrder.includes(4) || numOrder.includes(5)){
    updateRadioOption(1, sum) 
    updateRadioOption(0, sum) 
  } else if(numOrder.includes(3)){  
    updateRadioOption(0, sum)
  }  
}

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

// 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/136.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

create a getHighestDuplicates function which takes an array of numbers

Did you do this?

1 Like

oh… *face palm* thanks

1 Like