Tell us what’s happening:
Good afternoon. push me in which direction I should look. I try different ways, but nothing works.
For the last portion of the game, you will need to create an algorithm that checks for the presence of a straight. A small straight is when four of the dice have consecutive values in any order (Ex. in a roll of 41423
, we have 1234
) resulting in a score of 30
points. A large straight is when all five dice have consecutive values in any order (Ex. in a roll of 35124
, we have 12345
) resulting in a score of 40
points.
Declare a checkForStraights
function which accepts an array of numbers. If the user gets a large straight, update the fifth radio button with a score of 40
. If the user gets a small straight, update the fourth radio button with a score of 30
. If the user gets no straight, update the last radio button to display 0
.
Call your checkForStraights
function when the rollDiceBtn
is clicked to complete your dice game!
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
const checkForStraights = (array) => {
const reg = /^((1+)|(12))?(2|3)(3|4)4([1-4|6])?$/;
const regex = /^12345$/;
if (reg.test(array.sort((a, b) => a - b).join(""))){
updateRadioOption(3, 30);
}
else if (regex.test(array.sort((a, b) => a - b).join(""))) {
updateRadioOption(4, 40)
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
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/132.0.0.0 Safari/537.36
Challenge Information:
Review Algorithmic Thinking by Building a Dice Game - Step 14