I keep getting the hint :
“If no straight is rolled, your checkForStraights function should not enable the fourth or fifth radio button”
but my radio buttons are only enabled when a straight is rolled …am I missing something?
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
const checkForStraights = (arr) => {
arr.sort((a, b) => a - b);
let count = 0;
for (let i = 0; i <= arr.length; i++) {
if (arr[i] + 1 === arr[i + 1] ||
arr[-i - 1] === arr[i]) {
count++;
if (count === 5) {
updateRadioOption(3, 30);
updateRadioOption(4, 40)
} else if (count === 4) {
updateRadioOption(3, 30)
}
}
};
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 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 14
sorry for the late reply.
I agree, that little piece really doesn’t seem necessary, I found it when comparing my code to others to see what I was doing wrong, and my code doesn’t recognize the straights without it, though it should if I’m understanding all this correctly. I took my if/else if statement out of the loop and kept that little mirror snippet(since it wont pick up the straights otherwise) and i’m still getting the same hint when I check the code. I’m about to abandon the loop attempt and just compare the diceValuesArr to pre-declared arrays of straights. I’d really like to figure the loop out, but damn javascript can be frustrating
So I changed my code to what I mentioned above, and everything is working as it should in the preview, but now its telling me:
" If a small straight is rolled, your checkForStraights function should enable the fourth radio button, set the value to 30 , update the displayed text to , score = 30 and leave the fifth radio button disabled."
I know its gonna end up being something so incredibly simple (and stupid!) when I find it… I’ve had it with this dice game
revised code:
yes, you’re right, it still comes back as undefined, but it makes sense if my regex’s are just the straights themselves and not accounting for doubles being sorted together
here’s what I came up with, still getting undefined on the function console log and newOrder logs as [object Set]. is this moving in the right direction atleast? :