Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

First of all - sorry, i haven’t actually looked up similar questions since i would want to complete the challenge with the solutions i came up with.
The problem - i fill out an object with all encountered values and number of times they are encountered.
Then using Object.values(array).some i find out the value that’s encountered 3 or more times, but i can’t seem to be able to target a key of that value to calculate sum…

Your code so far

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

/* file: styles.css */

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

const getHighestDuplicates = (array) => {
  const counts = {};
  array.forEach(key => {
    counts[key] = (counts[key] || 0) + 1;
  });
  Object.values(counts).some(val => {
    if (val >= 3) {
      let sum = "(key * val) ... how to find key of that val?";
        updateRadioOption(0, sum);
      if (val >= 4) {
        updateRadioOption(1, sum);
      }
    } 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

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

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

  • do you think, “index” of this “array method would suffice”?

happy coding :slight_smile:

1 Like

thanks, now something happens, however something else doesn’t add up correctly, so i’m gonna troubleshoot it :sweat_smile:

1 Like

Alright, it finally passed, for a moment i had everything working correctly yet somehow challenge was still telling me that i need to update radios for 3s, 4s, and both at once.
Ironically what helped me is the solution from another thread

1 Like