Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

Cannot detect straights whatsoever no matter what.
const checkForStraights = (arr) => {
const counts = {};

for(const num of arr) {
counts[num] = counts[num] ? counts[num] + 1 : 1;
}
const keys = Object.keys(counts).join(‘’)

if (keys === ‘12345’ || keys === ‘23456’) {
updateRadioOption(4, 40);
}

if (keys.slice(0, 4) === ‘1234’ || keys.slice(0, 4) === ‘2345’ ||
keys.slice(1, 5) === ‘1234’ || keys.slice(1, 5) === ‘2345’) {
updateRadioOption(4, 30);
}
updateRadioOption(5, 0);
}

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (arr) => {
  const counts = {};

  for(const num of arr) {
    counts[num] = counts[num] ? counts[num] + 1 : 1;
  }
  const keys = Object.keys(counts).join('')

  if (keys === '12345' || keys === '23456') {
    updateRadioOption(4, 40);
  }

  if (keys.slice(0, 4) === '1234' || keys.slice(0, 4) === '2345' ||
      keys.slice(1, 5) === '1234' || keys.slice(1, 5) === '2345') {
    updateRadioOption(4, 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

Your browser information:

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

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

  • For a large straight, both radio buttons should be updated (edit, actually this requirement seems to have been removed).

  • For a small straight, the correct button should be updated (check the index you are passing).

If the user gets a large straight, update the fifth radio button with a score of 40 . If the user gets a small straight, update the fourth radio button with a score of 30 .