Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I’m not passing test 2 even though the requirements of that test all work on my end:
-Should enable the fourth radio button (done)
-Set the value to 30 (done)
-Update the displayed test to , score = 30 (done)
-Leave the fifth radio button disabled (done)

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (arr) => {

const sorted = arr.sort((a,b) => a-b);
const newSort = [...new Set(sorted)];
const strArr = String(newSort);
console.log(strArr)

if (strArr === "1,2,3,4,5" || strArr === "2,3,4,5,6") { 
  updateRadioOption(3, 30)
  updateRadioOption(4, 40);
  
}
else if (strArr === "1,2,3,4" || strArr === "2,3,4,5" || strArr === "3,4,5,6") {
  updateRadioOption(3, 30);
  scoreInputs[4].disabled = true;
} 
else {
scoreInputs[3].disabled = true
scoreInputs[4].disabled = true;
} 
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/140.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

test your function with [1, 2, 3, 4, 6]


const checkForStraights = (arr) => {

const sorted = arr.sort((a,b) => a-b);
const newSort = [...new Set(sorted)];
const strArr = String(newSort);
console.log(strArr)

if (strArr === "1,2,3,4,5" || strArr === "2,3,4,5,6") { 
  updateRadioOption(3, 30)
  updateRadioOption(4, 40);
  
}
else if (strArr === "1,2,3,4" || strArr === "2,3,4,5" || strArr === "3,4,5,6") {
  updateRadioOption(3, 30);
  scoreInputs[4].disabled = true;
} 
else {
scoreInputs[3].disabled = true
scoreInputs[4].disabled = true;
} 
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([1, 2, 3, 4, 6])
  }
}); 

When you say test your function with that array does that mean passing it as an argument into the function call, because I’ve done that and its still referencing diceValuesArr

call the function in the global space, not inside the event listener callback

ok I’ve called it in the global space, and also logged it to the console and it just says undefined

the function does not return anything, you wrote it like that

you need to check what it does

does it find the small straight?

no, it doesn’t return the small straight

you need to adjust the logic in your code so that small straights are individuated correctly

ok figured it out now