Tell us what’s happening:
HELPP!! Ive been on this for hours const checkForStraights = (arr) => {
const sorted = arr.slice().sort((a, b) => a - b);
const isConsecutive = (numbers) => {
for (let i = 1; i < numbers.length; i++) {
if (numbers[i] !== numbers[i - 1] + 1) {
return false;
}
}
return true;
};
if (sorted.length === 5 && isConsecutive(sorted)) {
updateRadioOption(4, 40);
updateRadioOption(3, 30);
} else {
const smallStraightPatterns = [
[1, 2, 3, 4],
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
const checkForStraights = (arr) => {
const sorted = arr.slice().sort((a, b) => a - b);
const isConsecutive = (numbers) => {
for (let i = 1; i < numbers.length; i++) {
if (numbers[i] !== numbers[i - 1] + 1) {
return false;
}
}
return true;
};
if (sorted.length === 5 && isConsecutive(sorted)) {
updateRadioOption(4, 40);
updateRadioOption(3, 30);
} else {
const smallStraightPatterns = [
[1, 2, 3, 4],
[2, 3, 4, 5],
[3, 4, 5, 6]
];
let isSmallStraight = false;
for (const pattern of smallStraightPatterns) {
if (pattern.every(num => sorted.includes(num))) {
isSmallStraight = true;
break;
}
}
if (isSmallStraight) {
updateRadioOption(3, 30);
} else {
updateRadioOption(3, 0);
}
updateRadioOption(4, 0);
}
};
const updateRadioOption = (index, score) => {
const input = scoreInputs[index];
const span = scoreSpans[index];
input.disabled = false;
input.value = score;
span.textContent = `, score = ${score}`;
};
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);
}
});
// User Editable Region
/* file: styles.css */
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