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

119
Vistas
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 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