Help. Noob at coding


#1

Hey All, Im new to coding and I’m stuck on the Javascript’s loops lesson. I got through it but i don’t understand why we have to use “i” for animals. For example the source code says that it uses the code “animals[i]” but i don’t see that in the source code below.



var animals = ["Grizzly Bear", "Sloth", "Sea Lion"];

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



#2

if you step the FOR LOOP, you get:

i=0;
i=1
i=2

at any step the console.log, inside the loop will have a new value of "i"
console.log(animals[i]) = console.log(animals[0])
console.log(animals[i]) = console.log(animals[1])
console.log(animals[i]) = console.log(animals[2])


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.