Tell us what’s happening:
I am so lost here. I’ve tried so many times to get the function correct but still getting “Your checkForStraights variable should be a function” keeps flagging and I cant get passed:
const checkForStraights = (arr) => {
let sorted = arr.sort((a, b) => a - b);
let counter = 1;
for (let i = 0; i < 4; i++) {
if (sorted[i] + 1 === sorted[i + 1]) {
counter++;
} else if (sorted[i] !== sorted[i + 1]) {
counter = 1;
}
}
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
function checkForStraights(arr) {
let sorted = arr.sort((a, b) => a - b);
let counter = 1;
for (let i = 0; i < 4; i++) {
if (sorted[i] + 1 === sorted[i + 1]) {
counter++;
} else if (sorted[i] !== sorted[i + 1]) {
counter = 1;
}
}
if (counter === 5) {
updateRadioOption(3, 40);
}
if (counter === 4) {
updateRadioOption(2, 30);
}
if (counter < 4) {
updateRadioOption(4, 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
/* 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/127.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 14