Tell us what’s happening:
I sort the incoming array from small to large, and then convert it into a string to match the rules. I passed in several arrays for testing and there was no problem. I read the code of the console: (4. If a large straight is rolled, your checkForStraights function should also enable the fourth radio button, set the value to 30, and update the displayed text to , score = 30.) This is a contradiction and I’m confused by it.
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
const checkForStraights =(array)=>{
for(let i=0;i<array.length;i++){
for(let j=i+1;j<array.length;j++){
if(array[j]<array[i]){
let temp = array[i];
array[i] = array[j];
array[j] = temp;
}
}
}
const regex4 = /1234|2345/g;
const regex5 = /12345/g;
const newstr = array.join("");
if(regex5.test(newstr)){
updateRadioOption(3, 30);
updateRadioOption(4, 40);
}else if(regex4.test(newstr)){
updateRadioOption(3, 30);
}else{
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
/* 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