Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

the checkForStraights has been a function, but the problem is ‘your checkForStraights variable should be a function’. its already function, what happend?

Your code so far

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

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

// Assign checkForStraights as a function
const checkForStraights = function (dice) {
    // Sort the dice array and remove duplicates
    const sortedDice = [...new Set(dice)].sort((a, b) => a - b);

    // Define sequences for small and large straights
    const smallStraightSequences = ["1234", "2345", "3456"];
    const largeStraightSequences = ["12345", "23456"];

    // Check for large straight
    const isLargeStraight = largeStraightSequences.includes(sortedDice.join(""));

    // Check for small straight
    let isSmallStraight = false;
    for (let seq of smallStraightSequences) {
        if (sortedDice.join("").includes(seq)) {
            isSmallStraight = true;
            break;
        }
    }

    // Update radio buttons
    const radioButtons = document.querySelectorAll('input[type=radio]');
    if (isLargeStraight) {
        radioButtons[4].value = 40;
        radioButtons[4].checked = true;
    } else if (isSmallStraight) {
        radioButtons[3].value = 30;
        radioButtons[3].checked = true;
    } else {
        radioButtons[5].value = 0;
        radioButtons[5].checked = true;
    }
};

// Add event listener to the rollDice button
const rollDiceBtn = document.getElementById('rollDiceBtn');
rollDiceBtn.addEventListener('click', () => {
    // Example dice roll - replace with actual dice roll logic
    const dice = [4, 1, 3, 2, 5]; // Replace with your dice roll logic
    checkForStraights(dice);
});


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);

  }
});

// 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/131.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

You have an error
Identifier 'rollDiceBtn' has already been declared. (172:6)

check line 8, and don’t declare it again