Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

My last issue is:
2. 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.
I’ve got a test case variable and when I pass it as the argument, the small straight functions as you’d expect so I really have no idea what the issue is.

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (arr) => {
  arr.sort((a, b) => a - b);
  const arrStr = arr.join('');

  const smallStraight = [1234, 2345, 3456];
  const largeStraight = [12345, 23456];


  if (largeStraight.some(straight => arrStr.includes(straight))) {
    updateRadioOption(4, 40);
    updateRadioOption(3, 30);
    updateRadioOption(5, 0);
  }
  if (smallStraight.some(straight => arrStr.includes(straight))) {
    updateRadioOption(3, 30);
    updateRadioOption(5, 0);
  }
  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

Your browser information:

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

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

1 Like

you are only missing one else in between the first if and the 2nd one

1 Like

i have added the “else” and removed it but still the same

can you share the new code?

1 Like

actually I found one other mistake. Here’s how you can find it too:

replace this line of code temporarily with this:

checkForStraights([3,2,4,5,4]);

and add this line of code:
console.log(arrStr);
just above this line:

then click the Roll button and see what radio buttons are enabled. (you will notice that the small straight is not enabled)

1 Like

the problem was in the duplicated numbers solved by

mod edit: code removed

Thanks

1 Like

exactly. Nicely done.
I’ve removed the correction you posted though to allow others to read this thread in the future without spoiling the full solution.

2 Likes

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