Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

i can’t understand how you should set the “, score = 0” and also what’s wrong here

Your code so far

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

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

const getHighestDuplicates = (dice) => {
  const counts = {};
  dice.forEach((value) => {
    counts[value] = (counts[value] || 0) + 1;
  });

  const totalScore = dice.reduce((sum, val) => sum + val, 0);
  let hasThreeOfKind = false;
  let hasFourOfKind = false;

  for (const value in counts) {
    if (counts[value] >= 4) {
      hasFourOfKind = true;
      updateRadioOption(1, totalScore);
      break;
    } else if (counts[value] >= 3) {
      hasThreeOfKind = true;
      updateRadioOption(0, totalScore);
    }
  }

  if (!hasThreeOfKind) {
    updateRadioOption(2, 0);
    scoreSpans[2].textContent = ", score = 0";
  }
};


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

// User Editable Region
/* file: styles.css */

Your browser information:

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

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

try to read through the instructions again and make sure you complete them all.
For eg this part is not complete:

Make sure to call your getHighestDuplicates when the dice are rolled.

You also need to use functions you’ve already written when needed. For eg. in order to follow this part of the instructions:

Regardless of the outcome, the final option should be updated with a score of 0

When they say to update an option, then you should use updateRadioOption function (you should call it with the option index and the score you want) This will set the score=0 that the hint is talking about. You should not be trying to do this manually as you were doing here for eg:

Thank you! This helped me so much

1 Like