Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

Your code so far

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

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

const checkForStraights = (arr) => {
  let largeStraight = arr.map(num => num).join("");
  let smallStraight = arr.map(num => num).join("").slice(0,-1);
     if (smallStraight === "1234" ||
        smallStraight === "2345" ||
        smallStraight === "3456" ||
        smallStraight === "6543" ||
        smallStraight === "5432" ||
        smallStraight === "4321") {
          updateRadioOption(3, 30);
        } else if (largeStraight === "12345" ||
        largeStraight === "23456" ||
        largeStraight === "54321" ||
        largeStraight === "65432") {
          updateRadioOption(4, 40);
        } else{
          updateRadioOption(5, score = 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 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

hi there, I see you posted some code but what is your question?

I don’t know exactly what I’m missing, but the code dosen’t seem to pass.
I keep getting the message " 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 ."

one thing you can do to check if your code is working as expected is to temporarily change this line of code to something like:

checkForStraights([2,3,1,6,4]);

Then click the roll button and see which radio buttons your code will enable.
(the small straight and the last radio button should both get enabled if your code is working)

from the given instruction, how does small straight pass with this call checkForStraights([2,3,1,6,4]), I thought it had to be either in an ascending or descending order. Please make it clearer to me.

when you roll the dice, the dice may land in any order.
the function checkForStraights should check the dice array to see if the dice rolls form a straight (in any order)

does checking for straights mean no duplicates of numbers in the array?

you can have duplicates. Like you can roll: 1 3 3 2 4 and that is still a straight

Can you explain what to roll a “straight” is, I believe I need to understad what it means to be able to pass this challenge.

why don’t you re-read the step and then come back and tell me what you think it means and then if that is incorrect, I will let you know?
I am not sure what it would help for me to repeat the same description that is already given in the step.

the instructions are clear, my problem is I dont think I understand what a straight means.

a straight is when you roll the dice in such a way that 4 or 5 of them form an unbroken series of sequential numbers.

1 Like

thanks, that helped me pass finally!
I was almost losing my mind :sweat_smile:

1 Like

I’m glad it clicked!

1 Like

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