The Table Weaver
EasyAcc. 91.8%
+20 XP 8
Multi-Level Multiplication
A single loop is powerful, but nested while loops allow you to weave complex sequences. By controlling two independent counters, you can process rows and columns separately.
The Assignment
Your function receives parameters rows and cols.
- Declare two variables:
i(outer) andj(inner), both starting at 1. - Write an outer
whileloop that continues whileiis less than or equal torows. - Inside the outer loop, ensure
jis reset to 1 before the inner loop starts. - Write an inner
whileloop that continues whilejis less than or equal tocols. - Inside the inner loop:
- Print the product of
iandj. - Advance the value of
j.
- Print the product of
- After the inner loop finishes, advance the value of
i.
01EXAMPLE 1
Input
rows=2, cols=5Output
1
2
3
4
5
2
4
6
8
10Explanation: Prints row 1 products, then row 2 products.
02EXAMPLE 2
Input
rows=1, cols=3Output
1
2
3Explanation: One row, three products.
Constraints
- Use strictly nested while loops.
- Print each product on a new line.
LoopsNested LoopsFundamentals
JavaScriptSystem handles I/O — write your function only
Loading...
3 Hidden
Input Arguments
rows2
cols5
Expected Output
1 2 3 4 5 2 4 6 8 10
Click RUN to test your solution