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

233
Visualizações
Udacity : Another Type of Loop Quiz /JS/Array/.forEach

I'm a beginner of JavaScript.I learn the course on Udacity. And there is a simple question about Array practice but I can't figure out why. I will be very appreciate if anyone can answer me,thanks!

practice:

  • Programming Quiz: Another Type of Loop (6-8)

  • QUIZ REQUIREMENTS

  • Use the existing test variable and write a forEach loop

  • that adds 100 to each number that is divisible by 3.

  • Things to note:

    • Inside the loop, you must use an if statement to verify code is divisible by 3
    • Inside the loop, you can update an element ONLY by using the arrayName[index]
    • Outside the loop, you can use console.log to verify the test variable */

    var test = [12, 929, 11, 3, 199, 1000, 7, 1, 24, 37, 4, 19, 300, 3775, 299, 36, 209, 148, 169, 299, 6, 109, 20, 58, 139, 59, 3, 1, 139 ];

Answer:

test.forEach(function (value,index,array){
    if (value % 3 ===0){
    array[index] +=100;
}
    return value;
});
console.log(test);   

My problem is why can't I use value +=100:

test.forEach(function (value,index,array){
    if (value % 3 ===0){
    value +=100;
}
return value;
});

what's the difference?

Thanks!!!!!!!!1

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