Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

HI Everyone, my code works on the console but I can’t finish the task. please help

const checkForStraights = (arr) => {
const sorted = arr.sort((a, b) => {return a - b})
let count = 0
for (let i = 0; i < sorted.length; i++) {
if (sorted[i + 1] - sorted[i] === 1) {
count++;
}
}
if (count === 4) {
updateRadioOption(3, 30)
updateRadioOption(4, 40);
} else if (count === 3) {
updateRadioOption(3, 30)
}
updateRadioOption(5, 0);
}

Your code so far

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

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

const checkForStraights = (arr) => {
  const sorted = arr.sort((a, b) => {return a - b})
  console.log(sorted);

  let count = 0
  for (let i = 0; i < sorted.length; i++) {
    if (sorted[i + 1] - sorted[i] === 1) {
      count++;
    }
  }
  console.log(count)
  if (count === 4) {
    updateRadioOption(3, 30)
    updateRadioOption(4, 40);
    
  } else if (count === 3) {
    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();
    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/134.0.0.0 Safari/537.36 Edg/134.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

Can you provide more info?

Whats the required output? What’s your output? Did you log some variables to the console to double check them? Did you log what arrays are being sent by the tests and how your function is treating them?

Welcome to the forum :wave:

1 Like

check what your app does with an array like [ 1, 2, 3, 5, 6 ]

Many thanks. my logic is wrong. I will start from scratch again. thanks