Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

I’m struggling a bit here. The code does seem to work in that it adds the message “, score = 0” to the last radio button but the checker tells me I still need to update this.

Your code so far

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

/* file: styles.css */

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

 const getHighestDuplicates = ()=>{
   let duplicates = {};
   let diceTotal = diceValuesArr.reduce((acc, el) => acc + el, 0);
  
  listOfAllDice.forEach(el => {
  if (duplicates.hasOwnProperty(el.textContent)) {
    duplicates[el.textContent]++;
  } else {
    duplicates[el.textContent] = 1;
  }

 });

   for (let key in duplicates){
    if(duplicates[key] >= 4){
      updateRadioOption(1,diceTotal)
    }
    else if(duplicates[key] >= 3) {
      updateRadioOption(0,diceTotal)
    }
    else  if(duplicates[key] < 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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

I just started reading the step and immediately noticed this problem. Your function doesn’t define any parameters but the step says:

create a getHighestDuplicates function which takes an array of numbers

Thanks. I resolved that by passing in the diceValuesArr array but I’m not sure why that suddenly meant that the “, score = 0” issue went away. All sorted though.