Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I am having difficulty with this last step. From what I can see my checkForStraights() function fulfills all the requirements but I still get “If a small straight is rolled, your checkForStraights function…” error when I try to check it. I don’t know if maybe there is a typo or syntaxError I am not seeing.
Any assistance would be greatly appreciated.
Thank you!

Your code so far

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

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

const checkForStraights = (arr) => {
  const sortedDice = arr.sort((a,b) => a-b);
  const diceNumber = Number(sortedDice.join(''));
  const smallStraight = [1234, 2345, 3456];

  for(let i=0; i<smallStraight.length; i++){
    if(diceNumber === smallStraight[i]){
    updateRadioOption(3, 30)
  };
  } 
  if(diceNumber === 12345 || 23456){
    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();
  }
});

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

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

Hi @adrian.ghari

diceNumber will contain 5 numbers, smallStraight only contains 4 numbers, so the two arrays will never equate.

There are other problems with your code.

Happy coding

Ah thank you for pointing that out!
I think I fixed that with includes, but the code still isn’t working.
You said there are other problems, can you point me in their direction?

const checkForStraights = (arr) => {
  const sortedDice = arr.sort((a,b) => a-b);
  const diceNumber = Number(sortedDice.join(''));
  const smallStraight = [1234, 2345, 3456];

  for(let i=0; i<smallStraight.length; i++){
    if(diceNumber.includes(smallStraight[i])){
    updateRadioOption(3, 30)
  };
  } 
  if(diceNumber === 12345 || 23456){
    updateRadioOption(3, 30);
    updateRadioOption(4, 40);
  }
  updateRadioOption(5, 0);
};

Nevermind I realize a problem with that instance of includes now haha, but I would still love it if you could give me some ideas of where the other problems lie.

Did you include an argument when calling the function?

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