Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I don’t understand here, should I need add if condition when no straight roll

Your code so far

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

/* file: styles.css */

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

function checkForStraights(arr) {
  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 (isSmallStraight) {
    updateRadioOption(3, 30);
  }
  if (isLargeStraight) {
    updateRadioOption(4, 40);
  }
  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);
    checkForStraights(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/127.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

Hi @magicturtlevn

Where are you getting the dice variable from?

Happy coding

1 Like

Thank you, I changed it to “arr” and I passed.

1 Like