Review Algorithmic Thinking by Building a Dice Game - Step 13

Tell us what’s happening:

Am i missing something? I am getting infinite loop detected on many of the previously done lines.
38, 103, 87, 20, 33, 51

Your code so far

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

/* file: styles.css */

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

const detectFullHouse = () => {
  let count = {};

  diceValuesArr.forEach(num => {
    count[num] = (count[num] || 0) + 1;
  });

  const counts = Object.values(count);

  if (counts.includes(3) && counts.includes(2)) {
    updateRadioOption(2, 25)
  } else {
    updateRadioOption(5, 0)
  }
};

const resetRadioOptions = () => {
  scoreInputs.forEach((input) => {
    input.disabled = true;
    input.checked = false;
  });

  scoreSpans.forEach((span) => {
    span.textContent = "";
  });
};

const resetGame = () => {
  diceValuesArr = [0, 0, 0, 0, 0];
  score = 0;
  round = 1;
  rolls = 0;

  listOfAllDice.forEach((dice, index) => {
    dice.textContent = diceValuesArr[index];
  });

  totalScore.textContent = score;
  scoreHistory.innerHTML = "";

  currentRoundRolls.textContent = rolls;
  currentRound.textContent = round;

  resetRadioOptions();
};

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);
  }
});

// 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 13

You have a slight mistake - your detectFullhouse function doesn’t take any arguments, but whey you call it, you pass diceValues array in it.

Apart from that, although my code is different from yours, the idea the same, and I think it should work well. Maybe fCC have some server-side problems, bc this code should pass.

My code is:

const detectFullHouse = () => {
  const count = {};
  const  getFrequency = (arr) => {
  for (let i = 0; i < arr.length; i++) {
    let ele = arr[i];
    if (count[ele]) {
        count[ele] += 1;
    } else {
        count[ele] = 1;
      }
    } 
    return count;
    }
  const valArr = Object.values(getFrequency(diceValuesArr));
  if (valArr.length === 2 && valArr.includes(3)) {
    updateRadioOption(2, 25);
  } else {
    updateRadioOption(5, 0);
  }
}

thank you, i guess i overlooked adding the arr as the parameter… it passed. It still shows the infinite loops detected but it passed. Thank you.

you know what is funny? My solution didn’t pass, and I (sorry) copied yours. It didn’t pass too.