Tell us what’s happening:
I wrote my code to count how many consecutive numbers are there in the sorted array. If the counter is either 4 or 5, it should call updateRadioOption with correct parameters.
However, the console keeps telling me that I’m wrong. Can you review my code to see what happened? Any help would be appreciated, thank you.
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const checkForStraights = (arr) => {
let counter = 1;
let ans = 1;
arr.sort((a, b) => a - b);
for(let i = 0; i < arr.length; i++) {
if(arr[i] != arr[i - 1]) {
if(arr[i] - arr[i - 1] == 1) {
counter++;
} else {
ans = Math.max(ans, counter);
counter = 1;
}
}
}
counter = Math.max(ans, counter);
console.log("sorted", arr);
console.log("counter", counter);
if(counter === 4) {
updateRadioOption(3, 30);
}
if(counter === 5) {
updateRadioOption(4, 40);
}
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 (Macintosh; Intel Mac OS X 10_15_7) 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