Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I am not getting any errors persé. I’ve walked through the function and I appear to be calling the correct condition blocks as and when a small or large straight appear. Apparently I’m failing test two, but I don’t know how to check this. It seems to be correct visually on the app. The logs aren’t throwing any errors.

I have searched through other forum posts, but no luck.

Help is appreciated.

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (arr) => {
  console.log(arr)
  debugger;
  let counter = 1;
	const sortedArray = [...new Set(arr)].toSorted((a, b) => a - b);
  const length = sortedArray.length;

  if (length < 4) {
    updateRadioOption(5,0)
    return
  }

  for (let i = 0; i < length; i++) {
    if (sortedArray[i] + 1 === sortedArray[i+1]) {
      counter++;
      continue
    }
    if (sortedArray[i] + 1 !== sortedArray[i+1] && counter <4) {
      updateRadioOption(5,0)
      return
    }
  }

  
  if (counter === 4) {
    updateRadioOption(3,30)
    
  }
  else {
    updateRadioOption(3,30)
    updateRadioOption(4,40)
  }
}


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

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

Welcome back to the forum @Codemiester

To help you debug, try adding some console logs where you are checking for a small straight.

Happy coding

1 Like

Hi Teller,

Thanks for the reply.

My current logs for the small straight show

image

The code segment triggering the second line in the console is below.

  if (counter === 4) {
    console.log(sortedArray)
    updateRadioOption(3,30)
    
  }
  else {
    updateRadioOption(3,30)
    updateRadioOption(4,40)
  }

I have extensively tested this code and I am confident that the straights are picked up correctly so I’m very confused.

do not use the debugger in the editor, instead run the tests with the browser console open, and see what are the editors printed right before the errors

so examine what your code does with 1,3,4,5,6 and 1,1,1,1,1

Thanks ILM. I’ve found the tests and now the bug. One test case failing. Thanks for your help!

you do not run the tests in the browser console, you use the usual button or keyboard shortcut, just keeping the browser console open. use console.log to print stuff to the console (like the console.log(arr) you have in the code you shared)

1 Like

Thanks ILM. My issue was that the “Selected context only“ checkbox was ticked which meant I was missing the dom-test-evaluator stuff. You’ve been really helpful. Thank you!