Tell us what’s happening:
I can’t understand why my code doesn’t pass the second test:
"2. If a small straight is rolled, your checkForStraights function should enable the fourth radio button, set the value to 30, update the displayed text to , score = 30 and leave the fifth radio button disabled. "
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const checkForStraights = arr => {
const sorted = arr.sort((a,b) => a-b)
console.log(sorted)
const distincts = sorted.filter((elem,index) => elem !== sorted[index+1])
console.log(distincts)
const cleared = []
for(let i=0; i<distincts.length ; i++){
if(i!==0 && distincts[i] - 1 === cleared[cleared.length-1]){
cleared.push(distincts[i])
}
else if(i === 0){ cleared.push(distincts[i])}
}
console.log(cleared)
if(cleared.length === 4) { console.log('entered here1');updateRadioOption(3, 30)}
else if(cleared.length === 5) {
console.log('entered here2')
updateRadioOption(3, 30);
updateRadioOption(4,40);
}
else {
updateRadioOption(5,0);
console.log('entered here3')}
}
//checkForStraights([5,1,6,3,2])
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/140.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 14