Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

My code is failing the case
4. If no straight is rolled, your checkForStraights function should not enable the fourth or fifth radio button.
and I can’t figure out why

Your code so far

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

/* file: styles.css */

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

const checkForStraights=(numArr)=>{
  let uniqueElem= [... new Set(numArr)].sort((a,b)=>a-b)
  let count=0
  for (let i=0;i<uniqueElem.length-1;i++){
    
      if(uniqueElem[i]+1===uniqueElem[i+1]){
        count+=1
      }
  }
  
  if(count===3){
    updateRadioOption(3, 30);
  }
  if(count===4){
    updateRadioOption(3, 30);
    updateRadioOption(4, 40);
  }
  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/134.0.0.0 Safari/537.36 Edg/134.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

if I adda console.log inside your if statemet

  if(count===3){
    console.log(numArr)
    updateRadioOption(3, 30);
  }

to see what sets of numbers are considered for this, I find that it shows these:

[ 1, 1, 2, 3, 4 ]
[ 2, 3, 4, 5, 5 ]
[ 3, 4, 5, 6, 6 ]
[ 1, 2, 3, 4, 6 ]
[ 1, 3, 4, 5, 6 ]
[ 1, 2, 2, 3, 4 ]
[ 2, 3, 3, 4, 5 ]
[ 3, 4, 5, 5, 6 ]
[ 1, 3, 2, 1, 4 ]
[ 5, 4, 3, 3, 2 ]
[ 3, 4, 5, 6, 1 ]
[ 1, 2, 3, 5, 6 ]

they all seem good until the last one, is that a straight?

Got It, thank you, I was not able to find a case that fails the condition.
Need to get better at finding edge cases.
Thanks for the help! need to change the logic a bit then. :sweat_smile: