Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

When i run tests my code seems to be working fine but it still fails the tests. i have tried multiple things but it still does not pass the test. Please help.

Your code so far

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

/* file: styles.css */

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

function checkForStraights(numbersArray) {
  let countingArray = [];
  let arrayCounter = 0;

  const isAwin =()=>{
    if(countingArray.length === 4){
      updateRadioOption(4, 40);
      updateRadioOption(3, 30);
      return true;
    }
    else if(countingArray.length === 3){
      updateRadioOption(3, 30);
      return true; 
    }
  }

      for(let i = 1; i < 5; i++){
        if(numbersArray[i]  - numbersArray[i - 1] ===1){
          countingArray[arrayCounter] = 1;
          console.log(countingArray);
          arrayCounter++;
        }
      }
      if (isAwin()) return;

  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([1,2,3,4,7]);
  }
});

// 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/127.0.0.0 Safari/537.36 Edg/127.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

what tests have you attemped other than this one?
For eg have you tried [5,3,1,2,4] ?

Have you passed all the preceding challenges, Im just checking because the entire file may be needed here.

just fyi, writing a function inside a function is not wrong.
Also the call the OP made to checkForStraights is in the correct place.

1 Like

Thx, I just realized the call should go in the click event.

Yes i have passed the preceding challenges.

1 Like

I have tried multiple tests and they all result in the right output in the console so i know that my function is properly checking for large straights and small straights.

and on top of that the program shows that the right value and index are being passed into the updateRadioButton () function when i use test cases that pass as either large straight or small straight.

i attached an image for the errors i am getting in console

Screenshot 2024-08-29 183908

But have you tried this test?

It does not pass for either large straight nor small straight

and have you realised why? (does testing with [5,3,1,2,4] help you realise it?)

Sorry I am still quite confused could you please give me more hints.

Earlier you said you tested the code and it was working?
Then I suggested you try a different test.
I gave you a list of numbers to try.
The idea is, you should try it and see what happens. The list I gave you is a large straight. So if your code is working, then it will recognize this and update the appropriate options.

Ok i understand now. I read the instructions wrong from the beginning so my code does what i thought it should be doing right but not what it should be really doing for it to pass. My code only checks for numbers in order that come one after the other not the ones that come in any order like the ones in the list you gave me. Thank you. I will go back and create a new algorithm from scratch and if i encounter any issues i will get back to you.

1 Like

So i added a bubble sort function right before the for loop and it passed. Thank you for your assistance.

1 Like

good job. For your ref. you could have just used a simple sort function too. Bubble-sort is a bit over-kill for 5 digits but good practice to do it.

1 Like