Tell us what’s happening:
I honestly don’t understand why my code isnt working. The largest straight portion should be right, but I am getting the error that says I a need to enable the fourth radio button when a small straight is rolled which is what I did and what happens when rolling the die. I dont understand what is wrong with my code.
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
const checkForStraights = (arr) => {
const sortedValues = [...new Set(diceValuesArr)].sort((a, b) => a - b);
console.log(sortedValues);
if (sortedValues.length === 5 && sortedValues[4] - sortedValues[0] === 4) {
updateRadioOption(4, 40);
updateRadioOption(3, 30);
}
else if (
(sortedValues.includes(1) && sortedValues.includes(2) && sortedValues.includes(3) && sortedValues.includes(4)) ||
(sortedValues.includes(2) && sortedValues.includes(3) && sortedValues.includes(4) && sortedValues.includes(5)) ||
(sortedValues.includes(3) && sortedValues.includes(4) && sortedValues.includes(5) && sortedValues.includes(6))
) {
updateRadioOption(3, 30); // Small straight: 30 points
}
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
/* 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/127.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 14