Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I am facing second error but i have tried this on consolelog it works for most and i haven’t found answers to this

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (arr) =>{
  const cleanArr = arr.sort().filter((el, i, a) => i === a.indexOf(el));
  

  const isStraight = (arr) => {
    let n = arr.length;

    for(let i = 1; i < n; i++){
      if(arr[i] !== arr[i - 1] + 1){
        return false;
      }
    } return true;
  }
  
  if(isStraight(cleanArr) && cleanArr.length === 4){
     updateRadioOption(3, 30);
  }else if(isStraight(cleanArr) && cleanArr.length === 5){
     updateRadioOption(3, 30);
     updateRadioOption(4, 40);
  }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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

Hi @rishabhr3007

If a small straight is rolled, your checkForStraights function should enable the fourth radio button, set the value to 30 , update the displayed text to , score = 30 and leave the fifth radio button disabled.

The last part means that the fifth radio button is also disabled.
The code logic is not allowing for that.

Happy coding

const disableRadioOption = (index, score) => {
scoreInputs[index].disabled = true;
scoreInputs[index].value = score;
scoreSpans[index].textContent = score;
}

i tried disabling the radio button but it’s not working

Hi @rishabhr3007

Declare a checkForStraights function which accepts an array of numbers. If the user gets a large straight, update the fifth radio button with a score of 40 . If the user gets a small straight, update the fourth radio button with a score of 30 . Regardless, it should always update the last radio button to display a score of 0, with the correct attributes.

If a small straight is rolled, your checkForStraights function should enable the fourth radio button, set the value to 30 , update the displayed text to , score = 30 and leave the fifth radio button disabled.

The hint message is a bit misleading. You can ignore the and leave the fifth radio button disabled part when updating the fourth radio button.

After setting the third and fourth radio buttons … Regardless, it should always update the last radio button to display a score of 0, with the correct attributes.

Your original post contained an else statement which prevents updating the fifth radio button for all cases.

Happy coding

did that but still having same error i think i am missing a point like where if array is containing small straight with one different number the code is not doing that part i was thinking of a for of loop that checks when array length is 5 it should check if there is four straight like 12346 it should do it. i am gonna do that now i think it would work then thankyou for your time and help.

It worked thankyou @Teller for your help

1 Like