Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

My code is working but it wont work help me pls:

// User Editable Region


### Your browser information:

User Agent is: <code>Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36 Edg/131.0.0.0</code>

### Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 14
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/review-algorithmic-thinking-by-building-a-dice-game/step-14`function checkForStraights(array) {
  const sortedStr = array.sort((a, b) => a - b).join("");
  if (/12345/.test(sortedStr)) { 
    updateRadioOption(4, 40); 
  } else if (/1234/.test(sortedStr)) {
    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++;
    res

### Your code so far


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

/* file: styles.css */

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

function checkForStraights(array) {
  const sortedStr = array.sort((a, b) => a - b).join("");
  if (/12345/.test(sortedStr)) { 
    updateRadioOption(4, 40); 
  } else if (/1234/.test(sortedStr)) {
    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);
  }
});`

can you remove extra content from the code blocks? I am not sure what is your code and what was accidentally added.

As a reminder, here how to format code blocks:

When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (').

Welcome to the forum @ThozamileMad

To help you debug, console log the following variable:

Happy coding

Okay I did as you said:

function checkForStraights(array) {
  const sortedStr = array.sort((a, b) => a - b).join("");
  if (/12345/.test(sortedStr)) { 
    updateRadioOption(4, 40); 
  } else if (/1234/.test(sortedStr)) {
    updateRadioOption(3, 30);
  } else {
    updateRadioOption(5, 0);
  }
}

Sorry for the sloppy request this is my first time asking for help.

1 Like

Let me post a new request my initial one was sloppy:

function checkForStraights(array) {
  const sortedStr = array.sort((a, b) => a - b).join("");
  console.log(sortedStr); 
  if (/12345/.test(sortedStr)) { 
    updateRadioOption(4, 40); 
  } else if (/1234/.test(sortedStr)) {
    updateRadioOption(3, 30);
  } else {
    updateRadioOption(5, 0);
  }
}

what values do you see for sortedStr?

11236, // No straight
11234 // Small straght (30)
13425 // Large straight (40)

you are missing at least one thing: if there is a large straight there is also a small straight, you need to enable both points

Thanks Ill have a look at it

but you should test array like these too: [3,4,5,6] and maybe 12234 etc… you should convert your array to a set or you should take repeated item from array and convert to an object. for example this is my code and it worked:

code removed by moderator

and do not forget add checkForStraights(diceValuesArr) to rollDiceBtn.addEventListener. there in else.

hi @trexylooke

It is great that you solved the challenge, but instead of posting your full working solution, it is best to stay focused on answering the original poster’s question(s) and help guide them with hints and suggestions to solve their own issues with the challenge. How to Help Someone with Their Code Using the Socratic Method

We are trying to cut back on the number of spoiler solutions found on the forum and instead focus on helping other campers with their questions and definitely not posting full working solutions.