Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

I’m trying to make the update with the previous builded function, but i’m not succeeding. What i’m doing wrong in my conditional statement?

Your code so far

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

/* file: styles.css */

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

const getHighestDuplicates = () => {
  let highestDuplicates = {};
  let sum = diceValuesArr.reduce((acc,el) => acc + el, 0)

  listOfAllDices.forEach(el => {
    if(highestDuplicates.hasOwnProperty(el.textContent)){
      highestDuplicates[el.textContent]++
    }else{
      highestDuplicates[el.textContent] = 1
    }
  })

  for (let key in highestDuplicates){
    if(highestDuplicates[key] >= 3){
      updateRadioOption(0,sum)
    }
    else if(highestDuplicates[key] >= 4) {
      updateRadioOption(1,sum)
    }
    else if(highestDuplicates[key] < 3){
      updateRadioOption(5,score)
    }
  }
}

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

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

Hello, when running your code a ReferenceError is being logged to the console. This usually happens when Javascript can’t find a reference to a variable in your code. In your case:

const listOfAllDice = document.querySelectorAll(".die");

The variable above is being written incorrectly.

Later you call this variable “listOfAllDices”, when it is declared as “listOfAllDice”. Fix the variable name, and see if that fixes your problems. :slight_smile:

I’ve fixed the variable name, and isn’t have a Referece Error problem anymore. But still have this message hint when i check my code:

When the array has less than three of the same number, your getHighestDuplicates function should update the final radio option with , score = 0

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.

I believe your answer is not being accepted because you are solving the exercise in a way that is different from the way that is being asked of you to solve it. When you are asked to write a function that receives an array of numbers, the exercise expects you to write a function that receives an array as an argument.
EX:

const myFunction = (myArrayParam) => {your code here}

The way you are currently solving the exercise has an arrow function (getHighestDuplicates) that is NOT receiving an array as an argument, therefore your answer is not being accepted. I could not find anything else wrong with your code, so i believe this is the only thing stopping your answer from being accepted. Please let me know if you run into any other problems or if you disagree. :slight_smile:

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.