Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

Code woun’t pass

Your code so far

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

/* file: styles.css */

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

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

  let isLargeStraight = false;
  let isSmallStraight = false;

  if (sortedArr.length === 5 && 
     (sortedArr.join('') === '12345' || sortedArr.join('') === '23456')){

    isLargeStraight = true;

  } else if (sortedArr.length >= 4) {
    const str = sortedArr.join('');
    if (str.includes('1234') || str.includes('2345') || str.includes('3456')) {

      isSmallStraight = true;
      
    };
  }

  if (isLargeStraight) {
    updateRadioOption(4, 40);
    scoreSpans[4].textContent = `, score = 40`; 
  } else if (isSmallStraight) {
    updateRadioOption(3, 30);
    scoreSpans[3].textContent = `, score = 30`;
  } else {
    updateRadioOption(5, 0); 
    scoreSpans[5].textContent = `, score = 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/128.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

I am sorry the code doesn’t pass.
What issue are you having fixing it so it can pass?

I do not understand what the problem is, kindly direct me

Keep in mind that a large straight is also a small straight (since a large straight includes a small one). So the large straight should update two buttons not just one.

Also the step may not have been clear but the last option with score 0 should be set each time the function is called regardless of whether a straight is found or not.

If you are still stuck, please share more information like what is shown in the console when you test or run.

Also do not add code to update the text content like you have here.
The only thing you need to do is call the updateRadioOption function and it should do the rest (confirm by reading through the code again and testing it).

Mod edit: code removed
Thanks hbar1st.

You’re welcome.
Instead of adding the same code to the if block and the else blocks, you could just have set the last radio button before or after the if statement (without including it in the if statement at all so you are not duplicating the same line of code everywhere).

I removed the code block you added in your post to avoid spoilers in the forum.

Thanks.

1 Like