Review Algorithmic Thinking by Building a Dice Game - Step 7

Tell us what’s happening:

hi, can you help me see what I’m doing wrong please?

Your code so far

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

/* file: styles.css */

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

const getHighestDuplicates = (numbers) => {

  const countObject = {};

   numbers.forEach((number) => {
    if (countObject[number]) {
      countObject[number]++;
    } else {
      countObject[number] = 1;
    }
  });

  const sum = numbers.reduce((a, b) => a + b, 0);

  if (highestCount >= 4) {
    updateRadioOption('fourOfAKind', sum);
  } else if (highestCount >= 3) {
    updateRadioOption('threeOfAKind', sum);
  } else {
    updateRadioOption('finalOption', 0);
  }
}

 

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

// User Editable Region

Your browser information:

El agente de usuario es: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36

Challenge Information:

Review Algorithmic Thinking by Building a Dice Game - Step 7

In English:

Hi there. There’s four issues with your code.

highestCount is never defined. Your code right now has no idea what the largest count is. You are tracking the numbers though as values in your countObject though. You need to determine which is the biggest.

The indexes given to the your updateRadioButton are not valid. The function needs a number. If you look to the side, you can see what order they are in. Note: All array indexes start at 0.

Thirdly a four of kind still technically counts as a three of a kind. So the available choices need to include “Three of a Kind”, “Four of a Kind” , and “None” which four of the same dice sides are showing. It’s not exclusive.

Lastly, your function call getHighestDuplicates needs the values of the dice passed. Otherwise it has no idea what it is comparing.

En español de Google Translate

Hola, ahí. Hay cuatro problemas con tu código.

Nunca se define el Count más alto. Su código ahora mismo no tiene idea de cuál es el mayor conteo. Usted está rastreando los números, aunque como valores en su “countObject”. Tienes que determinar cuál es el más grande.

Los índices dados a su “actualRadioButton”, no son válidos. La función necesita un número. Si miras a un lado, puedes ver en qué orden están. Nota: Todos los índices de matriz comienzan en 0.

En tercer lugar, un cuatro de tipo todavía técnicamente cuenta como un tipo de tres. Así que las opciones disponibles tienen que incluir “Tres de un tipo”, “Cuatro de un tipo” , y “Ninguno” que cuatro de los mismos lados de dados están mostrando. No es exclusivo.

Por último, su llamada de función “getHighestDuplicates”, necesita los valores de los dados pasados. De lo contrario no tiene ni idea de lo que está comparando.

1 Like