Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I have no clue why its not passing. when i roll a straight it does what it sould do: show the score, updates the value correctly, enables the right button/ buttons, and picking a score and clicking keep scores does correctly update the score. when i click the check your code button it tells me

  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”
  3. You should call the “checkForStraights” function when the “rollDiceBtn” is clicked

even though my code does do all of that

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (numArr) => {
  const sorted = numArr.sort((a, b) => a-b);
  console.log(sorted)
  const sortedStr = sorted.join("");
  console.log(sortedStr)
  if (sortedStr.includes("12345" || "23456")) {
    updateRadioOption(4, 40);
    updateRadioOption(3, 30);
  } else if (sortedStr.includes("1234" || "2345" || "3456")) {
    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);
    checkForStraights(diceValuesArr);
  }
});

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:135.0) Gecko/20100101 Firefox/135.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

What happens when you roll 1,3,2,3,4?

If I understand correctly this would have 1,2,3,4 small straight?

the dupe number did prevent it from detecting a small straight so i added a filter

const sorted = numArr.sort((a, b) => a-b).filter((num, pre, arr) => {
        return !pre || num != arr[pre - 1];
        });

now when i try to submit it gives me

  1. If a small straight is rolled, your “checkForStraights” function should enable the fourth radio button, set the value to “30”, update the displayed text to", score = 30"
    and leave the fifth radio button disabled.
  2. If a large straight is rolled, your “checkForStraights” function should enable the fourth button, set the value to “30”, update the displayed text to “, score = 30” . Additionally, the function should enable the fifth radio button, set the value to “40”, and update the displayed text to “, score = 40”.
  3. You should call the “checkForStraights” function when the “rollDiceBtn” is clicked.

additionally after failed test messages the console logs output (i manually put a gap between them for readability )

// console output
numArr = 1,1,2,3,4
Sorted = 1,2,3,4
Joined Sorted = 1234

numArr = 2,3,4,5,5
Sorted = 2,3,4,5
Joined Sorted = 2345

numArr = 1,2,3,4,5
Sorted = 1,2,3,4,5
Joined Sorted = 12345

numArr = 2,3,4,5,6
Sorted = 2,3,4,5,6
Joined Sorted = 23456

numArr = 1,4,4,4,4
Sorted = 1,4
Joined Sorted = 14

numArr = 2,2,3,3,3
Sorted = 2,3
Joined Sorted = 23

numArr = 5,5,5,5,5
Sorted = 5
Joined Sorted = 5

numArr = 6,5,1,5,6
Sorted = 1,5,6
Joined Sorted = 156

numArr = 1,2,3,5,6
Sorted = 1,2,3,5,6
Joined Sorted = 12356

numArr = 1,2,4,5,6
Sorted = 1,2,4,5,6
Joined Sorted = 12456

numArr = 1,2,2,3,5
Sorted = 1,2,3,5
Joined Sorted = 1235

numArr = 2,4,4,5,6
Sorted = 2,4,5,6
Joined Sorted = 2456

numArr = 1,5,6,2,3
Sorted = 1,2,3,5,6
Joined Sorted = 12356

numArr = 5,2,4,1,6
Sorted = 1,2,4,5,6
Joined Sorted = 12456

numArr = 2,1,5,3,2
Sorted = 1,2,3,5
Joined Sorted = 1235

numArr = 2,4,5,4,6
Sorted = 2,4,5,6
Joined Sorted = 2456

numArr = 1,1,1,1,1
Sorted = 1
Joined Sorted = 1

numArr = 5,3,6,4,2
Sorted = 2,3,4,5,6
Joined Sorted = 23456

These are indeed the test numbers.

Can you add another console.log to see if your function successfully classifies these as small straights or big straights?