Ziqi Zhou

Never marry your ideas, flirt with them.

Tag: loop

Identify “even” and “odd” numbers in an array

Use a nested for loop to take the numbers array below and replace all of the values that are divisible by 2 (even numbers) with the string “even” and all other numbers with the string “odd”.

var numbers = [
    [243, 12, 23, 12, 45, 45, 78, 66, 223, 3],
    [34, 2, 1, 553, 23, 4, 66, 23, 4, 55],
    [67, 56, 45, 553, 44, 55, 5, 428, 452, 3],
    [12, 31, 55, 445, 79, 44, 674, 224, 4, 21],
    [4, 2, 3, 52, 13, 51, 44, 1, 67, 5],
    [5, 65, 4, 5, 5, 6, 5, 43, 23, 4424],
    [74, 532, 6, 7, 35, 17, 89, 43, 43, 66],
    [53, 6, 89, 10, 23, 52, 111, 44, 109, 80],
    [67, 6, 53, 537, 2, 168, 16, 2, 1, 8],
    [76, 7, 9, 6, 3, 73, 77, 100, 56, 100]
];

See the Pen Nested Numbers by Ziqi Zhou (@IannaZhou) on CodePen.

 

Build a Triangle Using JavaScript

To create a triangle below, we can use function and loops in JavaScript.

* 
* * 
* * * 
* * * * 
* * * * * 
* * * * * * 
* * * * * * * 
* * * * * * * * 
* * * * * * * * * 
* * * * * * * * * *

 

See the Pen Build a Triangle by Ziqi Zhou (@IannaZhou) on CodePen.

 

Printing Out All the Seat Numbers in a Theater

Theater seats often display a row and seat number to help theatergoers find their seats. If there are 26 rows (0 to 25) and 100 seats (0 to 99) in each row, we can use a nested loop in JavaScript to print out all of the seat combinations in a theater.

0-0
0-1
0-2
...
25-97
25-98
25-99

See the Pen Printing Out All Seat Number in a Theater by Ziqi Zhou (@IannaZhou) on CodePen.

 

The “JuliaJames” Game and “99 Bottles of Juice” Song—Using Loops

By using loops, we can program our own version of FizzBuzz (in this case )called “JuliaJames”.

See the Pen The “JuliaJames” Game (“Fizzbuzz”) by Ziqi Zhou (@IannaZhou) on CodePen.

 

We can also write a loop that prints out the following song, starting at 99, and ending at 1 bottle.

 

See the Pen 99 Bottles of Juice Song by Ziqi Zhou (@IannaZhou) on CodePen.

 

© 2026 Ziqi Zhou

Theme by Anders NorenUp ↑