Tell us what’s happening:
Can someone tell me if I am on the right track with this step?
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const checkForStraights = (arr) => {
let straightCount = 0;
const sorted = arr.sort((a,b) => a - b);
sorted.forEach((num) => {
if(sorted[num] === sorted[num] - 1) {
straightCount++;
};
});
if (straightCount === 5) {
scoreInputs[4].disabled = false;
scoreInputs[3].disabled = false;
updateRadioOption(4, 40);
updateRadioOption(3, 30);
}
if (straightCount === 4) {
scoreInputs[3].disabled = false;
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; rv:131.0) Gecko/20100101 Firefox/131.0
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 14
hbar1st
October 16, 2024, 12:27pm
2
Try testing with different arrays like [2,3,2,1,4]
More like this then? Still not passing. Your way makes more since honestly. That has been my struggle with javascript when having to decide for myself the best method to use.
const checkForStraights = (arr) => {
const sorted = arr.sort((a,b) => a - b);
if(sorted === [1,2,3,4,5] || sorted === [2,3,4,5,6]) {
scoreInputs[4].disabled = false;
scoreInputs[3].disabled = false;
updateRadioOption(4, 40);
updateRadioOption(3, 30);
};
if (sorted === [1,2,3,4] || sorted === [2,3,4,5] || sorted === [3,4,5,6]) {
scoreInputs[3].disabled = false;
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);
}
});
I don’t want to suggest a method for you to use. I was attempting to suggest an array for you to test with to see if your code works though. Does it work with that array I suggested?
Are you asking if the updated code passes, or saying to try to pass in the array you provided to my function to see if it works in the console maybe?
Edit: Oh I see. I didn’t think of multiples in the sorted array.
1 Like
right, I was suggesting that you should test your code by hardcoding this array when you call the function just to see if your code can handle it.
Thank you for your tip! I got my code to pass finally!
1 Like
system
Closed
April 17, 2025, 2:59am
8
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.