Tell us what’s happening:
Hi all,
I’ve been struggling with this for quite a bit and don’t understand where my mistake(s) is.
The general flow of my checkForStraights function:
- sort the diceValuesArr in ascending order and then create a set, so duplicates are removed.
- define an array of arrays for both large and small straights
- iterate over each of these arrays and compare with the set from earlier. If they match, update the radio options as instructed.
Any feedback is appreciated.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const checkForStraights = (arr) => {
const sorted = arr.sort((a, b) => a - b);
const uniqueNumbers = [...new Set(sorted)];
const largeStraights = [[1, 2, 3, 4, 5], [2, 3, 4, 5, 6]];
const smallStraights = [[1, 2, 3, 4], [2, 3, 4, 5], [3, 4, 5, 6]];
for (let arr of largeStraights) {
if (arr === uniqueNumbers) {
updateRadioOption(4, 40);
updateRadioOption(3, 30);
break;
}
}
for (let arr of smallStraights) {
if (arr === uniqueNumbers) {
updateRadioOption(3, 30);
break;
}
}
}
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