Tell us what’s happening:
I am not getting any errors persé. I’ve walked through the function and I appear to be calling the correct condition blocks as and when a small or large straight appear. Apparently I’m failing test two, but I don’t know how to check this. It seems to be correct visually on the app. The logs aren’t throwing any errors.
I have searched through other forum posts, but no luck.
Help is appreciated.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const checkForStraights = (arr) => {
console.log(arr)
debugger;
let counter = 1;
const sortedArray = [...new Set(arr)].toSorted((a, b) => a - b);
const length = sortedArray.length;
if (length < 4) {
updateRadioOption(5,0)
return
}
for (let i = 0; i < length; i++) {
if (sortedArray[i] + 1 === sortedArray[i+1]) {
counter++;
continue
}
if (sortedArray[i] + 1 !== sortedArray[i+1] && counter <4) {
updateRadioOption(5,0)
return
}
}
if (counter === 4) {
updateRadioOption(3,30)
}
else {
updateRadioOption(3,30)
updateRadioOption(4,40)
}
}
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/141.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 14


