Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

Day 3 of trying to figure this out. I think my code is doing what’s asked but it’s not passing. my radio buttons seem to be updating correctly and disabling with new rolls (keeping radio buttons active did not pass either). I’ve tried updating the “none of the above” option in its own function, in the event listener, and in the getHighestDuplicates function both in the if else statement testing array.length and just updating it at the beginning of the function.

Your code so far

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

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


const resetInput = () => {
  scoreInputs[0].disabled = true;
  scoreSpans[0].textContent = ``;
  scoreInputs[1].disabled = true;
  scoreSpans[1].textContent = ``;
  scoreInputs[2].disabled = true;
  scoreSpans[2].textContent = ``;
  scoreInputs[3].disabled = true;
  scoreSpans[3].textContent = ``;
  scoreInputs[4].disabled = true;
  scoreSpans[4].textContent = ``;
}

const getHighestDuplicates = () => {
  
  let fourOfaKind = [];
  let threeOfaKind = [];
  let match = [];

  const sorted = diceValuesArr.sort();
  const diceTotal = diceValuesArr.reduce((a, b) => a + b, 0);

  for(let i = 0; i < sorted.length; i++) {

    if(sorted[i] === sorted[i + 1] && sorted[i] === sorted[i + 2] && sorted[i] === sorted[i + 3]) {
      fourOfaKind.push(sorted[i]);
    }else if(sorted[i] === sorted[i + 1] && sorted[i] === sorted[i + 2] && sorted[i] !== sorted[i - 1]) {
      threeOfaKind.push(sorted[i]);
    }else if(sorted[i] === sorted[i + 1] && sorted[i] !== sorted[i + 2] && sorted[i] !== sorted[i - 1]) {
      match.push(sorted[i]);
    }
  } 

  if(fourOfaKind.length === 1) {
    updateRadioOption(1, diceTotal);
    updateRadioOption(0, diceTotal);
    return;
  }else if(threeOfaKind.length === 1) {
    updateRadioOption(0, diceTotal);
    return;
  }
}

rollDiceBtn.addEventListener("click", () => {
  
  if (rolls === 3) {
    alert("You have made three rolls this round. Please select a score.");
  } else {
    rolls++;
    rollDice();
    resetInput();
    updateRadioOption(5, 0);
    getHighestDuplicates();
  }
});

// User Editable Region
/* file: styles.css */

Your browser information:

User Agent is: Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

Welcome to the forum, @tylerdamon1.

create a getHighestDuplicates function which takes an array of numbers

I suggest you RESET this step, reread the instructions, and only do what is asked. Nothing was mentioned about creating a resetInput() function or calling updateRadioOptions() within the rollDiceBtn event listener.

Oof. I got too stubborn with trying to make this work -.- i’ll have to back like you said. is there a reason it should be done with an array parameter as opposed to the way I did it? I’m sure what I did could be optimized better but it works. I guess my question is, if I were working in the development space would this code be acceptable or would it create problems, and how could it be done better?

Yes. The instructions need to be followed exactly in order to pass the tests.

1 Like