Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I wrote my function but when I call the inner function with the right parameters it doesn’t validate

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (arr) => {
  const sortedArr = arr.sort((a, b) => a - b);
  let counts = 0;

  for (let i = 0; i < sortedArr.length; i++) {
    if (sortedArr[i + 1] - sortedArr[i] === 1) {
      counts++;
    }
  }

  if (counts === 5) {
    updateRadioOtpion(4, 40);
  }

  if (counts === 4) {
    updateRadioOption(3, 30);
  }

  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 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

Welcome back to the forum @owonohermann54

You have a typo.
image

To help you debug, try console logging the counts variable, to the value after each roll.

Happy coding

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.