Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

61
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!