Review Algorithmic Thinking by Building a Dice Game - Step 14

Hey everyone :wave:

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);
  }
});

hi there, there’s a bug in this step. You must always enable the 5th radio button option when your function is called to pass.

Edit: also your function doesn’t really work to find straights?
I tested it by doing this:
checkForStraights([1,2,1,3,4]);

and it wasn’t able to detect a straight.

I just tried that. I changed

if (count === 5) {
    updateRadioOption(4, 40);
    updateRadioOption(3, 30);
  } else if (count === 4) {
    updateRadioOption(3, 30);
  } else {
    updateRadioOption(5, 0);
  }

to

if (count === 5) {
    updateRadioOption(4, 40);
    updateRadioOption(3, 30);
  } else if (count === 4) {
    updateRadioOption(4, 40);
    updateRadioOption(3, 30);
  } else {
    updateRadioOption(4, 40);
    updateRadioOption(5, 0);
  }

but that didn’t work. Is there a specific way I’m supposed to do it?

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)

1 Like

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!

1 Like

hi! i’m having the same warnings . i tried this:
checkForStraights([1,2,1,3,4]);
and it went through.
here is part of my code:

if (increment === 5){
console.log(‘large’);
updateRadioOption(4, 40);
updateRadioOption(3, 30);

}
if (increment === 4){
console.log(‘small’);
updateRadioOption(3, 30);
}

updateRadioOption(5, 0);

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.

Thank you.

1 Like