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

120
Visualizações
Assigning different colors to each element in an array

I have a variable named "classes" and basically, it contains classes like (apples,orange,grapes,mango) and this is coming from a txt file and being stored in a variable. The elements are printed on the webpage,but I want to assign each element in the set a different colour and I cant use random() because it will keep changing after i refresh the page, what I want to achieve is assigning random colours to each element in the Set and then the colours should become static and shouldn't keep changing after that.

Can someone please help how to achieve this either through html,css,or javascript.I am a beginner and I have to achieve this task fast.

Thank you

...

 <p id="classname"  ></p>



  #classname{
      text-align: right;
           }

  


                classes = annotationline[8];
                //pushing the elements in an array
               classarray.push(classes);
               //removing duplicates
                classset=new Set(classarray);
                console.log(classset);
                //printing it
                text = "";
                classset.forEach (function(value) {

                  text += value + "<br>";

                })
                    document.getElementById("classname").innerHTML = text;
                classarray.length = 0;
               })

...

about 4 years ago · Juan Pablo Isaza
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