Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I totally changed my logic and again it seems to work but for some reason I am still stuck and not getting it right :confused:
Any help would be welcome. Thanks :slight_smile:

Your code so far

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

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

};

const checkForStraights = (arr) => {
  const sortedArray = [...arr].sort((a,b) => a - b);
  console.log(sortedArray);
  const uniqueValuesArr = [...new Set(sortedArray)].join("");
  console.log(uniqueValuesArr);
  const smallStraight = ["1234", "2345", "3456"];
  const largeStraight = ["12345", "23456"];

  if (largeStraight.some(straight => uniqueValuesArr.includes(straight))) {
    updateRadioOption(4, 40); 
  } 
  else if (smallStraight.some(straight => uniqueValuesArr.includes(straight))) {
    updateRadioOption(3, 30); 
  } 
  else {
    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
/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

Try removing the else here and running the last update all the time.

1 Like

still not working :confused:

You haven’t mentioned what error you are getting or whether you tested the code or not so I’m just gonna keep guessing…

When you get a large straight, you need to update two radio buttons (plus the last one which always gets updated).

This is because a large straight also includes a small straight. So update your code and test to make sure it is working. You can hardcode the array you are passing the function to different values so you can confirm the code is behaving correctly each time.

2 Likes

Yessss, I finally got it! I wasn’t updating the small straight radio btn when I get the large straight, that was causing the problem!! Thanks so much!

2 Likes

Hello. I am having problem. :confused: :confused: :confused:

image

Can you please help me?

If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.

The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.

Thank you.