Tell us what’s happening:
Hey fCC Gang, Can anyone suggest where I am going wrong?
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const checkForStraights = (arr) => {
// Sorts dice array from lowest to highest
const sortedArr = listOfAllDice.sort((num1, num2) => num1 - num2);
console.log("Sorted from LOWEST to HIGHEST", sortedArr);
// Removes Duplicates & Creates a New Array
const sortedArr2 = [...new Set(sortedArr)].map(Number);
const joinedSortedArr = sortedArr2.join('');
const HighStraights = ['12345', '23456'];
const LowStraights = ['1234', '2345', '3456'];
// High Straight Detection - (12345, 23456)
if (HighStraights.includes(joinedSortedArr)) {
console.log("High Straight Detected!");
updateRadioOption(4, 40); // Update High Straight Radio Option
updateRadioOption(3, 30); // Update Low Straight Radio Option
scoreSpans[4].innerHTML = ", score = 40"; // Update innerHTML DOM for HS
scoreSpans[3].innerHTML = ", score = 30"; // Update innerHTML DOM for LS
}
// Low Straight Detection - (1234, 2345, 3456)
if (LowStraights.includes(joinedSortedArr)) {
console.log("Low Straight Detected!")
updateRadioOption(3, 30); // Update Low Straight Radio Option
scoreSpans[3].innerHTML = ", score = 30"; // Update innerHTML DOM
} else {
console.log("No Straight Detected:", sortedArr2);
}
// Updates last option regardless
updateRadioOption(5, 0);
scoreSpans[5].innerHTML = ", score = 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/132.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 14