Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

In the question it is given that when a large straight is rolled, we should enable the 5th radio button, set the value to 40, and update the displayed text accordingly. But in the hints, it is asking me to enable the 4th radio button and set the value to 30 when a large straight is rolled.

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (dice) => {
  const sortedDice = [...new Set(dice)].sort((a, b) => a - b);
  
  const largeStraight1 = [1, 2, 3, 4, 5];
  const largeStraight2 = [2, 3, 4, 5, 6];
  const isLargeStraight = largeStraight1.every(value => sortedDice.includes(value)) ||
                          largeStraight2.every(value => sortedDice.includes(value));

  const smallStraight1 = [1, 2, 3, 4];
  const smallStraight2 = [2, 3, 4, 5];
  const smallStraight3 = [3, 4, 5, 6];
  const isSmallStraight = smallStraight1.every(value => sortedDice.includes(value)) ||
                          smallStraight2.every(value => sortedDice.includes(value)) ||
                          smallStraight3.every(value => sortedDice.includes(value));
  if (isLargeStraight) {
    updateRadioOption(4, 40);
  } else if (isSmallStraight) {
    updateRadioOption(3, 30);
  } else {
    updateRadioOption(5, 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);

  }
});

// 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/126.0.0.0 Safari/537.36 Edg/126.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

I think you forgot to call the new function?

@hbar1st, I did call the function but it’s still the same error

Can you post the new eventListener block?

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);
checkForStraights(diceValuesArr);
}
});

Thanks. Have you tried to add some logs to log the value of isSmallStraight and isLargeStraight yet? Do they equal what you think they should when you test manually in the preview pane?

Welcome to the forum @shuklaayush628

If a large straight is rolled, your checkForStraights function should also enable the fourth radio button, set the value to 30 , and update the displayed text to , score = 30 .

If a large straight is rolled, the radio buttons for both small and large straights need to be enabled .

The else if logic is preventing that.

Also, the else block for the fifth radio button is not necessary.

Happy coding

Thank you. That worked perfectly !

1 Like