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

62
Vistas
Can I add strings in one array

I want to create a random color-picker with javascript and for that, I want random hex codes. The part with getting the hex codes is done but they appear as strings on different lines when I use console.log(); and not as one string on one line.

Does someone know how to change it? I already tried to set it as an array but it still appears on different lines because I used a for-loop and I can't change the name of the different strings because of that. Sorry for my poor explanation but here is the code for you to run it and maybe help me out:

let hexDigits = ["A", "B", "C", "D", "E", "F",
  "1", "2", "3", "4", "5", "6", "7", "8", "9"
];

for (let i = 0; i < 6; i++) {
  let hexColor = hexDigits[Math.floor(Math.random() * hexDigits.length)];

  console.log(hexColor);
}

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

0

Store to a string and append to it, printing only when you're done.

let hexDigits = ["A", "B", "C", "D", "E", "F",
  "1", "2", "3", "4", "5", "6", "7", "8", "9"
];

let hexColor = "";

for (let i = 0; i < 6; i++) {
  hexColor += hexDigits[Math.floor(Math.random() * hexDigits.length)];
}

console.log("#" + hexColor);

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