Tell us what’s happening:
Hi there! I’ve tried testing my solution with the following testing suite which I think is thorough. They pass all tests but for some reason the FCC testing deems it as not good.
x1234, x2345, x3456, 6543x, 5432x, 4321x
12345, 54321, 23456, 65432
Does anyone notice a problem which may arise with my solution?
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
const checkForStraights = (arr) => {
let straightCount = 1;
let increasing = false;
let decreasing = false;
for (let i = 0; i < arr.length - 1; i++){
if (arr[i] == arr[i + 1] - 1 && decreasing == false){
increasing = true;
straightCount += 1;
} else if (arr[i] == arr[i + 1] + 1 && increasing == false){
decreasing = true;
straightCount += 1;
} else {
if (i != 0) {
break;
}
}
}
if (straightCount == 4){
updateRadioOption(3, 30);
} else if (straightCount == 5){
updateRadioOption(4, 40);
} 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
The last radio button should be updated each time the function is called (there’s a bug in the step so it is not saying this but it is needed this way).
In addition: The largest straight, if found should update two radio buttons, the small and the large.
FYI, this question has been answered multiple times on the forum. Please consider searching before posting a question.
Thank you very much for the reply
if (straightCount == 4){
updateRadioOption(3, 30);
} else if (straightCount == 5){
updateRadioOption(4, 40);
updateRadioOption(3, 30);
}
updateRadioOption(5, 0);
Here is my updated checks as per your guidance, however it still doesn’t pass the test.
What does the hint say now? And have you tested your code to see if it works?
Edit: remember that a straight can be in any order. For eg. [5,3,4,1,2] is a straight.
Thank you for the input! However, I accounted for the decreasing straights within this for loop:
for (let i = 0; i < arr.length - 1; i++){
if (arr[i] == arr[i + 1] - 1 && decreasing == false){
increasing = true;
straightCount += 1;
} else if (arr[i] == arr[i + 1] + 1 && increasing == false){
decreasing = true;
straightCount += 1;
} else {
if (i != 0) {
break;
}
}
}
As mentioned in the initial post I used what I thought was a thorough testing suite. The hint has always said:
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
So there obviously must be something wrong but I can’t seem to figure it out since when I test it, the page behaves as it should.
Did you try testing with an array like the one I showed above? Neither increasing or decreasing?
Edit: to test: just modify the call to pass the hard coded array instead of diceValueArr and click the roll button to see if the correct radio buttons are enabled. Three radio buttons should be enabled for an array like [4,5,1,23]
Ohh I see now which case I missed. I wasn’t paying close attention when reading the question. Thank you very much! I didn’t realize that the dices didnt have to show in order.
So just to clarify 12345 and 41532 both work from what I now understand? Thank you for the help and prompt replies!
Yes the order should not matter as the die can show any order and still be a straight.