It keeps giving me the error below and i don’t undersatnd why, since if i try the code, it works fine:
2. 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.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const checkForStraights = (arr) => {
const counts = arr.sort((a,b) => a-b).join('');
if(counts === '12345' || counts === '23456'){
updateRadioOption(4, 40);
}
if (counts.slice(0,4) === '1234' || counts.slice(0,4) === '2345'){
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
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 OPR/118.0.0.0
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 14
It probably wouldn’t work since i’ve discovered that the code that i posted doesn’t like arrays with duplicates (unfortunally, i kept going after posting, so the code changed with the one below:
I’m not sure. As far i can tell (for now), the hard-coded solution should check all possibilities. I’ll keep trying and if it keeps not working, i’ll try a different approach, even if i think this one should be fine.
It goes directly for the updateRadioOption(5, 0);. I’ve tried to put a splice in the second if to cut the last index but it keeps going for the last updateRadioOptions.
It happens. Your code looks good. There’s just one more thing you need to consider with this approach. Have you satisfied all possible combinations in your hard-coded sequences?
Yeah. Good catch. So much for those hard-coded sequences…
Update: Actually, it could still be done, yes, the tests do pass with the hard-coded approach as long as long as all possible sequences and array patterns are considered.
All 3,4,5,6 cases wouldn’t work, since the code doesn’t take into consideration that pattern. So yeah, at this point i’m just missing what patterns are not working with the code.