So basically, I'm just trying to add 100 to the elements of the array test
that are divisible by 3 and print out the test
array. What I don't understand is that when I use console.log(test)
in the function, it prints out the array with the condition met ie 100 is added to the elements that are divisible by 3, but when I use it outside of the function, it doesn't. Why is that? And is there a way to print out the test array with the condition met outside the function? I just started learning javascript, so I'm kinda a beginner.
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
];
test.forEach(function(test){
if(test % 3 === 0){
test+=100;
}
console.log(test);//prints out test array if condition met
});
//console.log(test); //doesn't print test array with if condition met????