Review Algorithmic Thinking by Building a Dice Game - Step 14

Tell us what’s happening:

I’ve truly tried everything I can think of but it is still telling me to fix the small straight and activate the none of the above option when no straight is rolled :frowning:

Your code so far

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

/* file: styles.css */

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

const checkForStraights = (arr) => {
  const counts = {};
  const sorted = arr.sort((a,b)=> a-b);
  const diceNum = Number(sorted.join());
    if (diceNum === 1234 || 2345 || 3456){
    updateRadioOption(3, 30);
  } if (diceNum === 12345 || 23456){
    updateRadioOption(3, 30);
    updateRadioOption(4, 40);    
  } 
    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 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 14

this is not how you do comparisons (or this will not do what you think it will do).

the way this is being evaluated, the === is going to go first so let’s say diceNum was 245 for example, then the first thing that will happen is

245 === 1234

this will give false, then the next thing to happen is the OR so

false || 2345

this will give true because 2345 is a truthy.
So the radio button will get updated.

Hi @chowchow477

In addition to @hbar1st console log diceNum after you declare the variable.

Happy coding

1 Like
if (diceNum.includes(1234 || 2345 || 3456)){
updateRadioOption(3, 30); } if (diceNum.includes(12345 || 23456)){
updateRadioOption(4, 40);    

Now the program works but it will not pass…

your includes is not working as you would think.

for eg. here, this code is evaluated from the inner parenthesis first.
So the inner parenthesis says (1234 || 2345 || 3456) and this will evaluate to true.
then your includes is called with true as its parameter

1 Like