Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I’ve been at this for hours, the function is able to count the right amount of consecutive numbers and update what I think are the right radio buttons, but the console keeps telling me that I’m wrong. The instructions are so confusing sometimes. Any help would be appreciated, thank you.

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (arr) => {
  
  let consecutiveCount = 0;

  arr.forEach((num, index)=>{
    if(index === 0){
      consecutiveCount += 1;
      
      return;
    }
    
    if(num === arr[index -1] + 1){
      consecutiveCount += 1;
      
    }
  })

  if(consecutiveCount === 5){
    updateRadioOption(4, 40); 
  }
  if(consecutiveCount >= 4){
    updateRadioOption(3, 30); 
  }else{
    updateRadioOption(5, 0); 
  }
  return consecutiveCount;
}

console.log(checkForStraights([1,2,3,4,5]))

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 (X11; Linux x86_64) 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

Welcome to the forum @R4Y

If a small straight is rolled, your checkForStraights function should enable the fourth radio button, set the value to 30 , and …

update the displayed text to , score = 30 .

Happy coding

I have the same problem and used a similar algorithm as OP with counting the number of consecutives. I don’t get how your answer helps solve this? Could you explain?

The code works fine when tested and does exactly what it is supposed to.

Hey @R4Y ,
The code should check for a small straight which is when four of the dice have consecutive values in any order which mean [1,3,2,4], [4,2,3,1] and [2,3,5,4] should be considerd as samll straights. the case is the same for large straight. I hope this helps you finding what is the needed step to be done.
Happy Coding!

1 Like

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