Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

Currently failing 3 tests. These tests say I am not updating the corresponding radio buttons with their scores.
I cannot figure what I am doing wrong as in my preview, the needed buttons update with the correct scores and are no longer disabled.

Your code so far

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

/* file: styles.css */

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

const getDiceVals = () => {
  return Array.from(listOfAllDice).map(die => Number(die.textContent))
}

const sumOfDice = () => {
  return getDiceVals().reduce((acc, die) =>  acc + die, 0)
}

const clearInputs = () => {
  scoreInputs.forEach((input) => {
    input.disabled = true;
    input.value = 0;
  })
  scoreSpans.forEach((span) => {
    span.textContent = ``
  })
}

const getHighestDuplicates = (arr) => {
  
  const arrCounts = [0, 0, 0, 0, 0, 0]
  arr.forEach((item) => {
    arrCounts[item-1] = arrCounts[item-1] + 1 
  })

  arrCounts.forEach((count) => {
    if (count >= 4) {
      updateRadioOption(1, sumOfDice())
      updateRadioOption(0, sumOfDice())
    }
    if (count >= 3) {
      updateRadioOption(0, sumOfDice())
    }
  })

  updateRadioOption(5, 0)

}

rollDiceBtn.addEventListener("click", () => {
  if (rolls === 3) {
    alert("You have made three rolls this round. Please select a score.");
  } else {
    rolls++;
    rollDice();
    const diceValues = getDiceVals()
    updateStats();
    clearInputs()
    getHighestDuplicates(diceValues)
    
  }
});

// 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/138.0.0.0 Safari/537.36 Edg/138.0.0.0

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

I’m not sure exactly what your algorithm is, as it is not expected to need to write so much new code to be honest.
Can you share the entire file’s contents with us to begin with?

And try to think about this:
getHighestDuplicates is meant to use an array to determine what are the values in the dice. So nothing in this function or in its helper functions should be using anything else to figure that out.

(eg. if you need a helper called sumOfDice, then it should also be using a parameter of the same array of dice etc)

Thank you for your response.
I made some adjustments and eventually got it to work.
However, I find this question very awkward.
Since we are asked to invoke getHighestDuplicate, a function that required a param passed to it, I figured I needed to extract the values from the die array since no info on what should be passed to this function call other than it being an array (unless I missed that). Then I created a function to wipe the inputs of a previous roll because I figured that maybe that was the issue. Which is why the code has more than what was actually needed.

yeah you’re probably right that there is little to help you anticipate how the parameter is used. The way fCC’s test work, they need a ‘hook’ you could say to be able to test your function and at this point of the process, that hook is the arguments they can create to call the function with.

If you’d like to discuss this with the maintainers (provided this challenge is not part of the archived coursework), you can open an issue for this on the github repo.
Instructions below:

Thank you for helping make FCC better. Bugs can be reported as GitHub Issues. Whenever reporting a bug, please check first that there isn’t already an issue for it and provide as much detail as possible.