Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

I have tried several different methods but kept getting back that it wasn’t updating the inputs correctly. I switched to try this method but it is now telling me i don’t have the function at all. Where am i going wrong here? Please do not give me the answer. What method should i be looking at? Am i missing something?
I will comment down below with what i tried to use just before this. I want to understand where i am going wrong not just fix it…

Your code so far

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

/* file: styles.css */

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

const getHighestDuplicates = () => {
  let score = 0;
  for(let i = 0; i < diceValuesArr.length; i++){
    let count = 1;
    for(let j = 0; j < diceValuesArr.length; j++){
      if(j !=== i && diceValuesArr[i] === diceValuesArr[j]){
        count++;
      }
    };
    if(count >= 3){
      score = diceValuesArr.reduce((acc, val) => acc + val);
      updateRadioOption(0, score)
    } else if(count >= 4){
      score = diceValuesArr.reduce((acc, val) => acc + val);
      updateRadioOption(1, score)
    } else {
      updateRadioOption(5, 0)
    }
  }
};

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 (X11; Linux x86_64) 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

The way i tried just before this is…

const getHighestDuplicates = () => {

let highestDuplicate = 0;

diceValuesArr.forEach((num1, num2) => {

if (num1 === num2) {

highestDuplicate++;

}

})

let sum = diceValuesArr.reduce((acc, val) => acc + val, 0);

if (highestDuplicate < 3) {

updateRadioOption(-1, 0);

} else if (highestDuplicate = 3) {

updateRadioOption(0, sum);

} else if (highestDuplicate = 4) {

updateRadioOption(1, sum);

updateRadioOption(0, sum);

};

};

but this kept telling me i wasn’t updating the radio options correctly.

I tried a few other ways as well but kept getting the same response.

I’ve edited your code for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

create a getHighestDuplicates function which takes an array of numbers.

Your function needs to take an array of numbers as an argument.

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