Objective: To practice using for loops in JavaScript to create various geometric shapes in the console while employing pair programming techniques, specifically the "Ping Pong" method.
Pair programming is a collaborative coding practice where two programmers work together at one workstation. It is an effective way to share knowledge, improve code quality, and enhance team communication.
- Driver: The person who writes the code.
- Navigator: The person who reviews each line of code as it is typed, considers the overall direction, and provides insights on how to proceed.
In the "Ping Pong" approach, partners regularly switch roles. One partner writes a test, the other partner makes the test pass by writing code, and then they switch roles for the next test. For this lab, you’ll adapt this method for creating shapes:
- Partner A writes the for loop structure without filling in the logic.
- Partner B completes the logic to make the shape work.
- Switch roles for the next shape.
Work in pairs to create the following shapes in your JavaScript console using for loops. After completing a shape, switch roles for the next one.
-
Description: Create a horizontal line made of asterisks.
-
Expected Output: (for a line of length 5)
*****
-
Description: Create a square made of asterisks.
-
Expected Output: (for a 4x4 square)
**** **** **** ****
-
Description: Create a rectangle made of asterisks.
-
Expected Output: (for a 5x3 rectangle)
***** ***** *****
-
Description: Create a right-angled triangle.
-
Expected Output: (for a height of 4)
* ** *** ****
-
Description: Create an inverted right-angled triangle.
-
Expected Output: (for a height of 4)
**** *** ** *
-
Description: Create a diamond shape.
-
Expected Output: (for a width of 5)
* *** ***** *** *
- Submit a JavaScript file with your code.
- Include comments in your code to indicate which partner wrote each section.
- Include a brief reflection on the pair programming experience.