Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

im absolutely and utterly helpless. ignore the theatrics, this question has completetely failed me. please help

Your code so far

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

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

const checkForStraights = (arr) => {
  const sortedNumbersArr = arr((a, b) => a - b);
  const uniqueNumbersArr = [...new Set(sortedNumbersArr)];
  const uniqueNumbersStr = uniqueNumbersArr.join("");

  const smallStraightsArr = ["1234", "2345", "3456"];
  const largeStraightsArr = ["12345", "23456"];

  if (smallStraightsArr.some(straight => uniqueNumbersStr.includes(straight))) {
    updateRadioOption(3, 30);
  }

  if (largeStraightsArr.includes(uniqueNumbersStr)) {
    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();
  }
});

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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

1 Like

Here’s your function declaration:

and here’s where you’re calling it…

See the problem?

you forgot to chain the sort function to the ‘arr’ parameter

thank you guys let me try .

do you mean i left out the parameter (arr)?

Declare a checkForStraights function which accepts an array of numbers.

What does it mean that it “accepts an array of numbers”?

How does that relate to calling the function?

Yes, exactly. When you call checkForStraights, you need to pass in an array since your function definition requires an array to work. Also, I find it helpful to console.log() variables and conditionals if things aren’t working as expected.

1 Like

I stand corrected. Check out this recent response from the Community Manager: https://forum.freecodecamp.org/t/review-algorithmic-thinking-by-building-a-dice-game-step-7/734848/2?u=fcc4b6d10c4-b540-4e2

While your code will pass the tests when passing in the global diceValuesArr, it’s best practice to define your function with no parameter and reference the global diceValuesArr directly inside the function.

not always the Community Manager is right.
the tests will call the function with an argument, so you should have a parameter for that function

1 Like