Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

my test are working but everytime i submit i get warnings. i updated my updateRadipOption(5,0) for every time i click the button

here are the warnings:
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. ------- is this correct? 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.
### Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region



  if (increment === 5){
    console.log('large');
    updateRadioOption(4, 40);
    updateRadioOption(3, 30);
    
  } 
  if (increment === 4){
    console.log('small');
    updateRadioOption(3, 30);
  } 

 updateRadioOption(5, 0);
 
}

rollDiceBtn.addEventListener("click", () => {
  if (rolls === 3) {
    alert("You have made three rolls this round. Please select a score.");
  } else {
    rolls++;
    resetRadioOptions();
    // diceValuesArr = [1,2,3,4,5];
    rollDice();
    updateStats();
    getHighestDuplicates(diceValuesArr);
    detectFullHouse(diceValuesArr);
    checkForStraights(diceValuesArr);
  }
});



// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

can you share the whole function code that you wrote and not a snippet?

i have updated my code to run this array [3,4,5,6,0]

const checkForStraights = (arr) => {
  let baseNum;
  let increment = 1;
  let maxIncrement = 1;

  for (let x = 0; x < arr.length-1; x++){
    baseNum = arr[x];
    // console.log(baseNum, arr[x + 1]);
    if ( baseNum + 1 === arr[x + 1]){
      increment++;
      maxIncrement = Math.max(maxIncrement, increment);
      // console.log('+1', arr[x + 1], maxIncrement);
    } else if (arr[x] !== arr[x + 1]) {
      increment = 1;
    }
  }

  if (maxIncrement === 5){
    console.log('large');
    updateRadioOption(4, 40);
    updateRadioOption(3, 30);
  } 

  if (maxIncrement >= 4){
    console.log('small');
    updateRadioOption(3, 30);
  } 

 updateRadioOption(5, 0);
}
 
}

you have not tested enough.

Here’s how I tested your code:
checkForStraights([1,5,4,2,3]);

I replaced the call for checkForStraights with this hardcoded array. This array is a large straight as it has the numbers 1,2,3,4,5. Then I clicked the roll button but your function failed to enable the required radio options.

Try this method to test.

so it doesn’t have to be consecutive (exactly as it appears in the original array). that means i have to sort the array first then do the increment function. thank you i’ll rework my code.

1 Like

thank you! that did it. i sorted it first then did the rest. :smiling_face_with_three_hearts:

btw, there’s a typo on one of the warnings:

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. ------- is this correct? 0?

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.

1 Like