Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

Hi can someone tell me what I did wrong? I don’t get the right score on the right radio button… For my feeling I did it right

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (arr) => {
  arr.sort();
  let b = 0;
  for (let i = 1; i < arr.length; i++){
    if (arr[i] !== arr[i - 1] + 1){
      return false;
        } else {
          b++;
        }
    }
       if (b === 3){
      updateRadioOption(3, 30);
    } if (b === 4){
      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 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

In the mean while I removed the return false option.

const checkForStraights = (arr) => {
  arr.sort();
  let b = 0;
  for (let i = 1; i < arr.length; i++){
    if (arr[i] !== arr[i - 1] + 1){
      b;
        } else {
          b++;
        }
    }
    if (b === 3){
      updateRadioOption(3, 30);
    } if (b === 4){
      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);
  }
});

A large straight also includes a small straight so you should update two options for the large.
The last option for zero score should always be updated by this function in all cases. (Whether a straight id found or not)

1 Like

Perfect! Thanks a lot it worked!!

Mod edit : code removed

1 Like

Glad you passed. Just fyi: I removed the solution code from your post.

1 Like

Ahh okay I understand, no problem!

1 Like