Review Algorithmic Thinking by Building a Dice Game - Step 13

Tell us what’s happening:

ERROR MESSAGE: Sorry, your code does not pass. Keep trying.

When a full house is rolled, your detectFullHouse function should enable the third radio button, set its value to 25, and set the third span to display the text , score = 25.

The issue lies in the implementation of the detectFullHouse function and how it interacts with the radio button and span elements.

Your code so far

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

/* file: styles.css */

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

const detectFullHouse = (arr) => {
  const counts = {};

  // Count the occurrences of each number
  for (const num of arr) {
    counts[num] = counts[num] ? counts[num] + 1 : 1;
  }

  const values = Object.values(counts);
  const hasThreeOfAKind = values.includes(3);
  const hasPair = values.includes(2);

  // If a full house (three of one number, two of another) is rolled
  if (hasThreeOfAKind && hasPair) {
    // Enable third radio button, set value to 25
    scoreInputs[2].disabled = false;
    scoreInputs[2].value = 25;
    
    // Set text to ", score = 25"
    scoreSpans[2].textContent = `, score = 25`;
  } else {
    // Reset third radio button and span
    scoreInputs[2].disabled = false;
    scoreInputs[2].value = 0;
    scoreSpans[2].textContent = `, score = 0`;
  }

  // Always reset the last radio button to score = 0
  scoreInputs[5].disabled = false;
  scoreInputs[5].value = 0;
  scoreSpans[5].textContent = `, score = 0`;
};

rollDiceBtn.addEventListener("click", () => {
  if (rolls === 3) {
    alert("You have made three rolls this round. Please select a score.");
  } else {
    rolls++;
    resetRadioOptions();
    rollDice();
    updateStats();
    getHighestDuplicates(diceValuesArr);
    detectFullHouse(diceValuesArr);  // Call detectFullHouse after rolling the dice
  }
});


// 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/131.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 13

Hi @ovodofred

You can use the updateRadioOption function.

Happy coding

Hi, @Teller, thanks for reaching out but I’m afraid I’m not sure what you mean.
The error message indicates that the resetRadioOptions function is not defined, and this is causing the code to break. meaning the resetRadioOptions function is supposed to reset all the radio buttons, but it’s missing or not declared in my current code, whereas it is and it’s value is rightly set to 25 so, I don’t know why I keep receiving the error message.

I got it, the detectFullHouse function was meant to be updated to include updateRadioOption(5, 0) to always update the final radio button to score = 0, regardless of whether a full house was detected. Previously, this condition was not met consistently.