Tell us what’s happening:
Hello, I believe this code should work because the loop checks if the value + 1 is equal to the value after it (sorted). So after doing that, if count is equal to 5 or more, then it enables the correct radio buttons, otherwise if count is equal to 4 or more, then it enables the small straight and none of the above radio options. After that, if none match the none radio option is enabled. Maybe I have a typo? I have tried the game out a bit, and the straights seem to work. Thank you.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const checkForStraights = (arr) => {
let count = 1;
const array = arr.sort((a, b) => a-b);
for(let i = 0; i < array.length-1; i++) {
if(array[i+1] === array[i]+1) {
count++;
} else if(array[i+1] !== array[i]) {
count = 1;
};
};
if(count >= 5) {
updateRadioOption(4, 40);
updateRadioOption(3, 30);
updateRadioOption(5, 0);
} else if(count >= 4) {
updateRadioOption(3, 30);
updateRadioOption(5, 0);
} else {
updateRadioOption(5, 0);
}
};
//[1, 2, 3, 4, 5]
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