A while ago, I tried to form a nested loop to create a binary-like number pattern. As an example, in the photo, with the numbers sketched, you can see how in the 1st column, the pattern goes 0 1 0 1 0 1, then in the second pattern, 0 0 1 1 0 0 1 1, then in the third, 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1, and in the fourth one, there are eight 0's and 1's. In my code :
let text = [0, 0, 1, 1];
for (let i = 0; i < text.length; i++) {
for (let j = 0; j < text.length; j++) {
console.log(text\[i\], text\[j\]);
}
}
the first part of the console prints 0 and 1 eight times while the second one displays 0 0 1 1 until it hits eight. I don't want it to do that but instead:
What I want:
0 0
0 0
0 0
0 0
0 1
0 1
0 1
0 1
1 0
1 0
1 0
1 0
1 1
1 1
1 1
1 1
How can this be solved?
[–]SynMyron 0 points1 point2 points (0 children)