Tell us what’s happening:
I have tried a couple of different approaches to this, and neither seems to pass the test even though, on the surface at least, they give correct results. Any insight and help would be greatly appreciated. What am I missing here?
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const checkForStraights = (arr) => {
let previousNum;
let maxConsecutiveCount = 0;
let currConsecutiveCount = 0;
arr.forEach((el, index) => {
if (index === 0) {
previousNum = el;
} else {
if (Math.abs(el - previousNum) === 1) {
previousNum = el;
currConsecutiveCount++;
if (currConsecutiveCount > maxConsecutiveCount) {
maxConsecutiveCount = currConsecutiveCount;
}
} else {
previousNum = el;
currConsecutiveCount = 0;
}
}
});
if(maxConsecutiveCount === 4) {
updateRadioOption(4, 40);
updateRadioOption(3, 30);
} else if (maxConsecutiveCount === 3) {
updateRadioOption(3, 30);
} 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
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 14