Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I honestly don’t understand why my code isnt working. The largest straight portion should be right, but I am getting the error that says I a need to enable the fourth radio button when a small straight is rolled which is what I did and what happens when rolling the die. I dont understand what is wrong with my code.

Your code so far

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

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

const checkForStraights = (arr) => {
  const sortedValues = [...new Set(diceValuesArr)].sort((a, b) => a - b);
  console.log(sortedValues);
  if (sortedValues.length === 5 && sortedValues[4] - sortedValues[0] === 4) {
    updateRadioOption(4, 40);
    updateRadioOption(3, 30);
  }
  else if (
    (sortedValues.includes(1) && sortedValues.includes(2) && sortedValues.includes(3) && sortedValues.includes(4)) ||
    (sortedValues.includes(2) && sortedValues.includes(3) && sortedValues.includes(4) && sortedValues.includes(5)) ||
    (sortedValues.includes(3) && sortedValues.includes(4) && sortedValues.includes(5) && sortedValues.includes(6))
  ) {
    updateRadioOption(3, 30); // Small straight: 30 points
  } 
  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/127.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

fyi, there’s a bug in this step and you actually need to run this code all the time when your function is called (not just in the else statement).

I’ll try your code to see if there is anything else.

You’re using diceValuesArr but passing it as arr in your function. Make sure you’re using consistent names so everything matches up.

1 Like

Make sure you’re updating the correct radio buttons. If the small straight should be option 3, and the large straight is option 4, ensure you’re updating the right ones.

i think the problem is here. You are relying on diceValuesArr instead of relying on the input parameter that you called arr