Finn Finn - 7 months ago 12
Javascript Question

How would I turn this forEach to a forLoop?

so I know that the colors and color are different but I don't really know how to go about changing it to a forLoop function.

var numbers = [1,2,3,4,5,6,7,8,9,10];
var colors = ["red", "orange", "yellow", "green"]

numbers.forEach(function(color){
if(color% 3 ===0) {
console.log(color);
}
});

Answer
var numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
var colors = ["red", "orange", "yellow", "green"];

for (var i = 0; i < numbers.length; i++) {
  if (numbers[i] % 3 === 0) {
    console.log(numbers[i]);
  }
}