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

397
Visualizações
Looping through arrays. Rainbow Text Exercise

Need help. I attached the image of the question, This is the image of the code:

// This is the given code:

const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];
// I written these:

const spans = document.querySelector('h1 span');

for(let rainbow of spans){
    spans.style.color = " ";
}
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You should use document.querySelectorAll('h1 span') to get all span item.

Then you can use Array.forEach to get character and index. Then you map the index to the colors array.

// This is the given code:
const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet'];

// I written these:
const spans = document.querySelectorAll('h1 span');
spans.forEach((item, index) => {
  item.style.color = colors[index];
})
<h1>
  <span>R</span>
  <span>A</span>
  <span>I</span>
  <span>N</span>
  <span>B</span>
  <span>O</span>
  <span>W</span>
</h1>

about 4 years ago · Juan Pablo Isaza Relatório

0

const colors = ['red', 'orange', 'yellow', 'green', 'blue', 'indigo', 'violet']; 
//PLEASE DON'T CHANGE THIS LINE!

//YOU CODE GOES HERE:

const letters = document.querySelectorAll('span')enter code here

let count = 0

for (let letter of letters){
    letter.style.color = colors[count]
    count += 1
}
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