Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I am getting the following error

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.

even though It is working for the small straight.

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (arr) =>{
  let f=0;
  for(let i=0; i<4; i++){
    if(arr[i]+1 === arr[i+1]){
      f++;
    }
  }
  if(f===3){
    updateRadioOption(3,30);
  }else if(f===4){
    updateRadioOption(4,40);
  }
  console.log(f)
  updateRadioOption(5, 0);
};
 let arr2=[1,3,4,5,6];
 checkForStraights(arr2);


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/135.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

Quote
The out put for [1,3,4,5,6]

and what does it do for these?

[ 1, 3, 2, 1, 4 ]
[ 5, 3, 6, 4, 2 ]

none of the above option.

I think I should sort it.

Now it is showing small straight for the first input , and full straight for the 2nd input,

but the error still persists

what does the error say exactly?

const checkForStraights = (arr) =>{
  arr.sort();
  let f=0;
  for(let i=0; i<4; i++){
    if(arr[i]+1 === arr[i+1]){
      f++;
      
    }
  }
  if(f===3){
    updateRadioOption(3,30);
  }else if(f===4){
    updateRadioOption(3,30);
    updateRadioOption(4,40);
  }

  updateRadioOption(5, 0);
};

Currently the error is
If no straight is rolled, your checkForStraights function should not enable the fourth or fifth radio button.

Though I am satisfying this condition too.

[ 1, 2, 3, 5, 6 ]

test this

What if the user rolls [2,3,3,5,4]? Does your code handle that?

updated code as

const checkForStraights = (arr) =>{
  console.log("before sort "+arr);
  arr.sort();
  let f=0;
  console.log(arr);
  for(let i=0; i<4; i++){
    if(arr[i]+1 === arr[i+1]){
      f++;
      
    }else{
      if(f<3)
      {
      f=0;
      }
    }
    console.log(f);
  }
  if(f===3){
    updateRadioOption(3,30);
  }else if(f===4){
    updateRadioOption(3,30);
    updateRadioOption(4,40);
  }

  updateRadioOption(5, 0);
};

Output is none of the above

None of the above option.

but now I am getting this error

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.

ok, and now…

[ 1, 2, 2, 3, 4 ]

what does your function do with this?

none of the above, score = 0

Ok, but what does this tell you?

and do you think that is correct?

1 Like

I thought that wasn’t suppose to satisfy it

Thank you.