I don't understand the output of this question from CodeAcademy. It is stated in the for loop that X+=1, but why is the output printing the X index 0 for the second time? I thought it would be index 1(A) as X+=1.
const tags = ['G', 'A', 'T',' C'];
for (let x = 0; x < tags.length; x +=1) {
for(let y = 1; y < tags.length - 1; y +=1) {
console.log(`${tags[x]}${tags[y]}`,x,y);
}
}
//output GA GT AA AT TA TT CA CT
Output:
The inner loop starts with y = 1 and ends with y = 2 for this tags array. That means for each iteration of the outer loop, the console.log runs twice. That's why you are seeing 4 * 2 = 8 outputs printed out, where 4 is the number of iterations the outer loop goes through, and 2 is the number of iterations the inner loop goes through each time.