Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

it keeps telling me this.

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

  2. 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.

but my code is working properly. can anyone enlighten me what the issue is here?

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (array) => {
  const sortedArr = array.sort((a, b) => a - b);
  console.log(sortedArr);

  const uniqueSortedArr = [...new Set(sortedArr)].join("");
  console.log(uniqueSortedArr);

  const smallStraight = uniqueSortedArr.includes(1234 || 2345 || 3456);
  const largeStraight = uniqueSortedArr.includes(12345 || 23456);
  console.log(smallStraight, largeStraight);

  if(largeStraight){
    updateRadioOption(4, 40);
    updateRadioOption(3, 30);
    updateRadioOption(5, 0);
  } else if(smallStraight){
    updateRadioOption(3, 30);
    updateRadioOption(5, 0);
  } 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(diceValueArr);
  }
});

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

Hi there!

The way you’re checking for the small and large straights (1234 || 2345 || 3456 and 12345 || 23456) will not work correctly. The || operator is being applied incorrectly. You need to check whether the string uniqueSortedArr contains any of these specific sequences of digits, not using the || operator like this.
Use the correct strings ("1234"), ("2345"), etc., instead of 1234, which were not behaving as intended.

In the checkForStraights function, you are passing diceValueArr to checkForStraights, but the variable in the rollDiceBtn event listener is diceValuesArr. It’s a small typo.
Correct the variable name.

Hello!
i tried it that way and it still doesn’t work. I did it in the string way before as well. but it showed this. so i tried it using || operator.

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

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

. 4. 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

i also updated the diceValuesArr typo.

and it also shows false in the console even if the roll is small or large straight. and doesn’t update the radio options

[ 1, 3, 4, 4, 6 ]
1346
false false
[ 1, 2, 2, 3, 4 ]
1234
false false

but when i use the || operator it does shows true and updates the radio.

[ 1, 1, 3, 5, 6 ]
1356
false false
[ 1, 2, 2, 3, 4 ]
1234
true false

Just try to change the numbers to strings here.

And correct array name within the function call.

i did that but it still doesn’t pass. i also corrected the typo. it does not pass.

.includes accepts only one argument, so checking multiple patterns simultaneously will not work.
Use Array.some() to iterate over potential patterns.

copy the array using slice method.

Call the updateRadioOption(5,0) only in the else block.