0

When I use the Alert it's working. But When I use Console.log it doesn't print anything.

I tried switching the alert with the console.log

var myColor = ["Red", "Green", "White", "Black"];

for (i = 0; i < myColor.length; i++) {
    console.log(myColor);
}
VLAZ
  • 22,934
  • 9
  • 44
  • 60
Dani
  • 1
  • 2

1 Answers1

0

You need to change the syntax a bit var myColor = ["Red", "Green", "White", "Black"];

for (i = 0; i < myColor.length; i++) {
    console.log(myColor[i]);
}

Alternately you can also use for...of loop to print colors

var myColor = ["Red", "Green", "White", "Black"];
    for(const color of myColor){
    console.log(color);
    }
Jithin P
  • 655
  • 2
  • 10
  • 25