Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I think my code is working correctly. But it does not pass. I don’t know what I’m missing. I have seen that many people are trying it with .join() and checking the straight options, instead I check if the number is consecutive to the next one in the array. I have tried it with several arrays and it works and does what they ask. can anyone help me? Thanks

Your code so far

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

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

const checkForStraights = (arr) => {
  const orderedArr = [...new Set(arr)].sort((a, b) => a - b);

  let checkNum = orderedArr[0];
  let continuousCount = 0;

  for (let i = 0; i < orderedArr.length; i++) {
    if (orderedArr[i] === checkNum) {
      checkNum++;
      continuousCount++;
    }
  }

  if (continuousCount === 5) {
    updateRadioOption(4, 40);
    updateRadioOption(3, 30);
  } else if (continuousCount === 4) {
    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
/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

What about array like [4, 6, 3, 5, 1]?

Thanks, I didn’t notice that array. I think I fix it now, but still not working.

const checkForStraights = (arr) => {
  const orderedArr = [...new Set(arr)].sort((a,b)=>a-b);

  let continuousCount = 1;

  for (let i=1; i<orderedArr.length;i++){
    debugger;
    if (orderedArr[i]===orderedArr[i-1]+1) {
      continuousCount++;
    } 
    else {
      continuousCount = 1;
    }
  }

  if (continuousCount === 5) {
    updateRadioOption(4, 40);
    updateRadioOption(3, 30);
  } else if (continuousCount === 4) {
    updateRadioOption(3, 30);
  } else {
    updateRadioOption(5, 0);
  }
};

This error is display:

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.

I thin is not workin cause of this “leave the fifth radio button disabled.”, but when i press “Roll the dice” button, are already reset all the radio buttons

what happens here if you have an array like [1, 2, 3, 4, 6]?

Thank you very much, I have solved it. Finally. Thanks for your troubleshooting arrays I was able to fix it and it works.