Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

93
Vistas
How can I store data for a line of numbers logic?

So basically I have this code in a discord bot that'll appear in general-chat, and it says "Guess the correct number from 1-10" and it's a random number each time.

So, what this code is supposed to do, is every time a incorrect number is guessed, it'll update the "line of numbers" to make it slightly obvious what the number is.

Example: They guess numbers 1, 4, 5, and 7.

The embed should look like

1 _ _ 4 5 _ 7 _ _ _, but what's happening is that it doesn't save every single guess, so it'll only update the embed with the last guessed number

_ _ _ _ _ _ 7 _ _ _ ( like this ), so how can I store all of the incorrect guessed answers, to work like how I want it to?

code: https://www.toptal.com/developers/hastebin/rowexaketi.js

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can have an array with all the guesses that go wrong. Create that array in a scope that is visible for your function, and than you use the includes method to check if that number was tried before.

Example:

const triedNumbers = [5,9,10]; // Start it as empty array, this is just for testing
const possibleValues = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
    
// Use reduce instead of mapping to transform the array into a string later
const finalString = possibleValues.reduce((accumulated, current) => {
    if(triedNumbers.includes(current)) return `${accumulated}${current}`;
    return `${accumulated}_`;
}, '');

console.log(finalString);

Link to reduce docs.

A couple of suggestions: change the variables names of your code, you have multiple indexes: index, index3, index4, which makes really difficult to read and understand how your code is working. Also, if you are creating variables that are not going to be mutated later, use const instead of let.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda