Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

Hey everyone,
I don’t know why my code is not working I have tried doing it in multiple ways too and I always get these errors:
If a small straight is rolled, your checkForStraights function should enable the fourth radio button, set the value to 30, and update the displayed text to , score = 30. and 2 more similar errors.

Your code so far

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

/* file: styles.css */

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

const checkForStraights = arr => {
  let count = 0;
    
  for (let i = 0; i < 3; i++) {
    if (arr[i] === arr[i + 1] - 1 && arr[i + 1] === arr[i + 2] - 1) {
      count++;
    }
  }
console.log(count);
  if (count === 2) {
    updateRadioOption(3, 30);
  } else if (count === 3) {
    updateRadioOption(3, 30);
    updateRadioOption(4, 40);
  }

  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/128.0.0.0 Safari/537.36 Edg/128.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

Do you understand what a straight is?
Have you tried testing your code by hard-coding an array and passing it to the function to confirm it is working correctly?

I tested it and it worked for arrays like [1,2,3,4,5] and [1,2,3,4,6], but it doesn’t work for arrays like [4,3,2,1,5]

So the dice array is not ordered. Which means your code has to work for any list of numbers even if they are not in order. Please work with that idea and modify your code.

1 Like

I tried using the sort method and it worked .
Thank you for helping me!

1 Like