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

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