Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

Even after multiple different algorithms the compiler shows the following error: 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. I am even though calling the update radion function for small straight and large straight

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (arr) => {
  const sortedValues = [...new Set(diceValues)].sort((a, b) => a - b);
  
  // Check for large straight
  if (sortedValues.length === 5 && sortedValues[4] - sortedValues[0] === 4) {
    updateRadioButton(4, 40);
    return;
  }
  
  // Check for small straight
  for (let i = 0; i <= sortedValues.length - 4; i++) {
    if (sortedValues[i + 3] - sortedValues[i] === 3) {
      updateRadioButton(3, 30);
      return;
    }
  }
  
  // No straight
  updateRadioButton(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/126.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

The first thing I notice is that your logic in the for condition may not work as you would want.

Did you add any console.logs to check if the second if runs?

You didn’t added the code as per instructions