Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

Task is to create function to check for small and large straights and prime appropriate radio buttons.What is wrong?

Your code so far

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

/* file: styles.css */

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

function checkForStraights(arr) {
  let count = 1;

  for (let i = 1; i < arr.length; i++) {

    if (arr[i] === arr[i - 1] + 1) {

      count++;

      if (count === 6) {
        updateRadioOption(5, 40);
        updateRadioOption(4, 30);
        updateRadioOption(6, 0);

      } else if (count === 5) {
        updateRadioOption(4, 30);
        updateRadioOption(6, 0);
      }

    } else if (count === 1) {
      updateRadioOption(6, 0);
    }

  }
}

console.log(checkForStraights);

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 Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36 Edg/143.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

1 Like

What makes you say something is wrong with it?

Welcome back

Call your function with an array to test it. You can use an array with the numbers in the example here:

A small straight is when four of the dice have consecutive values in any order (Ex. in a roll of 41423, we have 1234) resulting in a score of 30 points.

Use console.log() in your function to see if the correct if block is capturing the input.

You can comment out the updateRadioOption lines for testing.

There are only 5 radio options. Remember, arrays start at index 0.