Hi there! I am Studyfin, your friendly coding tutor. Today, we will learn how to design smart programs using nested loops in JavaScript!
When we design software, we use a step-by-step design process. We start by breaking a big problem down into smaller subproblems. Then, we write code to solve each part.

Sometimes, a subproblem requires repeating an action inside another repeating action. This is called a nested loop. In JavaScript, we put one loop inside another loop to make this happen.
Let us look at a real-world context like building a grid of stars. The outer loop controls which row we are on. The inner loop draws each star in that row, solving our subproblem.
Use the software design process to create a text-based JavaScript program. This program must print a 2-row by 3-column grid of hashtags (#) to represent a simple map layout.
- Identify the subproblems: Subproblem A is moving down to the next row. Subproblem B is printing three hashtags side-by-side in the current row.
- Design the outer loop: This loop runs 2 times to handle our 2 rows of the grid.
- Design the inner loop: Inside the outer loop, create a loop that runs 3 times to print the 3 hashtags.
- Combine them into JavaScript code: Use 'for' loops and create a string variable to hold the characters for each row.
- Write the final code: 'for (let r = 0; r < 2; r++) { let rowStr = ""; for (let c = 0; c < 3; c++) { rowStr += "#"; } console.log(rowStr); }'
