Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

Please, help me with this step.
My counter variable shows the expected results (it counts how much consecutive numbers are there among the dice), but I still can’t pass the challenge, it still says that when there is a small or a large straight the corresponding radio button should be updated

Your code so far

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

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

const checkForStraights = (arr) => {
  let sorted = arr.sort((a, b) => a - b);
  let counter = 0;
  for (let i = 0; i < 5; i++) {
  if (sorted[i] + 1 == sorted[i + 1]) {counter++}
  else {counter === 1}
  }

  if (counter === 5)
       { updateRadioOption(4, 40)
        };
  if (counter === 4) {
      updateRadioOption(3, 30)
  }
  if (counter < 4) {
      updateRadioOption(5, 0)
  }

// User Editable Region
/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Linux; Android 10; K) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Mobile Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

You should update this button if you have 5 numbers too because 5 includes 4

1 Like

Thank you. Done :saluting_face:

  if (counter >= 4) {
      updateRadioOption(3, 30)
}

Unfortunately, the code still doesn’t pass

I’m stupid, I had to use 4 instead of 5 and 3 instead of 4

@JackLantern You are not stupid. You are just dealing with the difficulties of learning a new language :slight_smile: .

1 Like

Thank you, @evaristoc :pray:
I was just a little bit upset that my mistake was so primitive :slightly_smiling_face:
You are absolutely right, I don’t think that a stupid person would learn JS :thinking: