I’m having an issue with the last step of “Review Algorithmic Thinking by Building a Dice Game” in the JS course. When I submit the code below, my answer is not accepted and I receive the message:
If a small straight is rolled, your checkForStraights function should enable the fourth radio button, set the value to 30 , and update the displayed text to , score = 30 .
The console prints:
// running tests
If a small straight is rolled, your checkForStraights function should enable the fourth radio button, set the value to 30, and update the displayed text to , score = 30.
If a large straight is rolled, your checkForStraights function should enable the fifth radio button, set the value to 40, and update the displayed text to , score = 0.
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.
// tests completed
The issue is that, as far as I can tell, my code does fulfill all of the above requirements, and I don’t know why it’s not being accepted. I’ve tried various tests and everything came back fine. Please let me know what the issue is, and thanks!
const checkForStraights = (diceValuesArray) => {
let count = 1;
for (let i = 1; i < diceValuesArray.length; i++) {
if (diceValuesArray[i - 1] === diceValuesArray[i] - 1) {
count++;
} else if (count < 4) {
count = 1;
}
}
if (count === 5) {
updateRadioOption(4, 40);
updateRadioOption(3, 30);
} else if (count === 4) {
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);
}
});
you will need to fix your algorithm to detect the straights as it doesn’t work right now.
(for eg try passing it [2,3,1,5,4] and see what it does when you click roll)
Also you will need to update the last radio button all the time. (every time the function is called)
Ah. I misunderstood what was meant by a straight. I thought the consecutive numbers had to be in consecutive slots (i.e. [1, 2, 3, 4, 5] works but [1, 3, 2, 4, 5] doesn’t.) My bad. Thanks for the clarification!
If you have a question about a specific challenge as it relates to your written code for that challenge and need some help, click the Ask for Help button located on the challenge (it looks like a question mark). This button only appears if you have tried to submit an answer at least three times.
The Ask for Help button will create a new topic with all code you have written and include a link to the challenge also. You will still be able to ask any questions in the post before submitting it to the forum.