Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

63
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda