freeCodeCamp icon indicating copy to clipboard operation
freeCodeCamp copied to clipboard

dice game (js beta) - step 13 instructions are incorrect

Open hbar1st opened this issue 6 months ago • 1 comments

Describe the Issue

in step 13 of the dice game (js beta), the instructions say:

Your detectFullHouse function should check if the user has rolled three of one number and two of another number. If so, it should update the third radio button to display a score of 25, with the correct attributes. If not, it should update the last radio button to display a score of 0, with the correct attributes.

However when we look at the code in the following step 14 for this function we see this:

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

  for (const num of arr) {
    counts[num] = counts[num] ? counts[num] + 1 : 1;
  }

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

  if (hasThreeOfAKind && hasPair) {
    updateRadioOption(2, 25);
  }

  updateRadioOption(5, 0);
};

Notice how the last radio button is updated regardless of the full house check? But the instructions said: "If not, it should update the last radio button...". People are trying to follow this instruction and failing and not understanding why (they use an if-else statement for example as in the code below)

Affected Page

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/review-algorithmic-thinking-by-building-a-dice-game/step-13

Your code

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

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

  for (const num of diceValuesArr) {
    if (counts[num]) {
      counts[num]++;
    } else {
      counts[num] = 1;
    }
  }

  const values = Object.values(counts);
  if (values.includes(3) && values.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();
  }
});

// User Editable Region

Expected behavior

The instructions should be changed to match the requested code:

Your detectFullHouse function should check if the user has rolled three of one number and two of another number. If so, it should update the third radio button to display a score of 25, with the correct attributes. It should also update the last radio button to display a score of 0, with the correct attributes.

However, I noticed that the functions getHighestDuplicates and detectFullHouse are both updating the last radio button. So it seems like one of these need not do that? (so we could just not ask for this in this step since it is gonna get updated elsewhere anyway?)

Screenshots

No response

System

N/A

Additional context

I noticed this issue when I was attempting to help a camper on the forum: https://forum.freecodecamp.org/t/review-algorithmic-thinking-by-building-a-dice-game-step-13/704683/2

https://forum.freecodecamp.org/t/review-algorithmic-thinking-by-building-a-dice-game-step-13/700417/4?u=hbar1st

hbar1st avatar Aug 05 '24 19:08 hbar1st