Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

230
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!