Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I seem to be getting the correct behavior to pass all the test but for some reason i get this message in the console:

“If a small straight is rolled, your checkForStraights function should enable the fourth radio button, set the value to 30, update the displayed text to , score = 30 and leave the fifth radio button disabled.”

on small straights (small only, not large) the fourth button is enabled and the fifth button is disabled and it shows “score = 30”.

I can’t figure out the problem.

Your code so far

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

/* file: styles.css */

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

function checkForStraights(arr) {
  const sortedNumString = arr.sort((a, b) => a - b).join("")

  const smallStraightTest1 = /1234/.test(sortedNumString);
  const smallStraightTest2 = /2345/.test(sortedNumString);
  const smallStraightTest3 = /3456/.test(sortedNumString);
  const largeStraightTest1 = /12345/.test(sortedNumString);
  const largeStraightTest2 = /23456/.test(sortedNumString);

  if (largeStraightTest1 || largeStraightTest2) {
    updateRadioOption(4, 40);
  } 
  
  if (smallStraightTest1 || smallStraightTest2 || smallStraightTest3) {
    updateRadioOption(3, 30);
  } 
    
  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

Your browser information:

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

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

Welcome to the forum @bgoree1

A large straight contains a small straight.

Happy coding

1 Like

I was able to solve the problem by converting the array to a Set to remove duplicate values, then I sorted those unique values so my tests would work correctly.

function checkForStraights(arr) {
  const numSet = new Set(arr);
  const sortedNumString = [...numSet].sort((a, b) => a - b).join("");
   

  const smallStraightTest1 = /1234/.test(sortedNumString);
  const smallStraightTest2 = /2345/.test(sortedNumString);
  const smallStraightTest3 = /3456/.test(sortedNumString);
  const largeStraightTest1 = /12345/.test(sortedNumString);
  const largeStraightTest2 = /23456/.test(sortedNumString);

  if (largeStraightTest1 || largeStraightTest2) {
    updateRadioOption(4, 40);
  } 
  
  if (smallStraightTest1 || smallStraightTest2 || smallStraightTest3) {
    updateRadioOption(3, 30);
  } 
    
  updateRadioOption(5, 0);
}
1 Like