The 9.7.4 leash exercise is a graphics-programming activity that helps students understand how interactive objects move and respond to mouse input. It combines fundamental programming concepts, including variables, functions, coordinates, graphical objects, and event handling, in a small visual project.
The central idea is to create a ball and a line that behaves like a leash, connecting a fixed point to a moving object.
For beginners, this exercise provides a practical way to understand how code controls objects on a screen. Instead of simply displaying a static image, the program responds to movement, updates coordinates, and changes the visual relationship between different elements.
Learning how these parts work together makes it easier to approach more advanced graphics projects, animations, and interactive applications.

Quick Information Table
| Information | Details |
|---|---|
| Main keyword | 9.7.4 leash |
| Topic | Interactive graphics programming |
| Learning environment | CodeHS-style JavaScript graphics |
| Main visual elements | A ball and a connecting line |
| Core programming language | JavaScript-style syntax |
| Main concepts | Variables, functions, coordinates, graphics, and events |
| User interaction | Mouse movement |
| Primary objective | Keep the moving object and line visually connected |
| Difficulty level | Beginner |
| Practical applications | Animation, interactive graphics, and simple games |
| Main challenge | Updating object positions and line endpoints correctly |

What Is the 9.7.4 Leash Exercise?
The 9.7.4 leash exercise is commonly associated with a beginner-level programming task in which students create a graphical object connected to a line. In the commonly described version, a circle follows the mouse while a line stretches between the circle and a fixed point on the canvas.
The exercise demonstrates how a program can respond to real-time user input. When the mouse moves, its coordinates change. The program reads those coordinates and updates the position of the circle and the endpoint of the line.
The term leash describes the visual relationship between these elements. It is a programming metaphor rather than a reference to a physical dog leash or a specific leash product.
The exact requirements may vary depending on the course version and assignment instructions. Students should therefore use the instructions in their own exercise to confirm the required object sizes, starting positions, colors, and behavior.
Why Is This Exercise Important?
This activity brings several foundational concepts together in one manageable project.
- Variables: Store references to graphical objects and keep track of important values.
- Functions: Organize the setup and movement logic into reusable sections.
- Coordinates: Determine where graphical objects appear on the canvas.
- Event handling: Respond when the user moves the mouse.
- Object manipulation: Change the position or endpoint of an existing graphic.
- Debugging: Identify and correct errors that prevent the animation from working as intended.
Understanding these concepts is more valuable than memorizing a single solution because the same techniques appear in many other interactive programming assignments.
How the 9.7.4 Leash Program Works
The basic program can be understood through two main stages: initial setup and continuous updates.
1. Creating the Graphics Objects
The first stage creates the circle and the line. The circle represents the moving object, while the line represents the leash. In a typical JavaScript graphics environment, a circle can be created with a Circle object and a line with a Line object. The program then assigns their starting positions and adds them to the canvas.
A circle’s position generally refers to its center, while a line is defined by two endpoints. Understanding this distinction helps prevent alignment problems. These are standard graphics operations in the CodeHS JavaScript graphics environment.
2. Setting the Initial Position
The objects need sensible starting coordinates before mouse interaction begins. A canvas has a horizontal axis, represented by x, and a vertical axis, represented by y. In the usual screen coordinate system:
- Increasing the x-coordinate moves an object to the right.
- Decreasing the x-coordinate moves an object to the left.
- Increasing the y-coordinate moves an object downward.
- Decreasing the y-coordinate moves an object upward.
If the circle begins at the center of the canvas, the coordinates can be calculated using the canvas width and height. For example, the center is represented by:
var centerX = getWidth() / 2;
var centerY = getHeight() / 2;
These values can be used to position the circle and establish the fixed end of the leash. The actual starting coordinates should match the assignment’s requirements.
3. Responding to Mouse Movement
The interactive portion of the exercise uses a mouse-movement event. When the pointer moves, the program receives updated coordinates. In the relevant graphics environment, a mouse event can provide the current horizontal and vertical positions through methods such as getX() and getY().
A registered mouse-movement handler can use these values to update the graphics. The process follows a simple sequence:
- The user moves the mouse.
- The program receives the mouse event.
- The event handler reads the pointer’s coordinates.
- The circle moves to the new position.
- The line’s endpoint is updated to match.
- The screen displays the updated arrangement.
This sequence repeats whenever another mouse-movement event occurs.
4. Keeping the Line Connected
The line is the defining feature of the leash exercise. It must visually connect the fixed point to the moving circle. If the circle moves but the line remains unchanged, the connection breaks. If the line moves incorrectly, it may appear detached from the circle or anchored at the wrong location.
The solution is to update the line’s endpoint using the same coordinates used to position the circle. The line’s fixed endpoint should remain unchanged if the assignment specifies a stationary anchor.
Key Features of the 9.7.4 Leash Exercise
Although the project is small, it introduces several important features of interactive software.
Interactive Movement
The circle responds to mouse input rather than following a predetermined animation path. This helps students understand the relationship between user actions and program behavior. Unlike a static drawing, an interactive graphic changes as the user moves the pointer. The program must continuously respond to new information instead of relying on one initial set of coordinates.
Real-Time Coordinate Updates
The program uses changing coordinate values to determine where the circle should appear. This is a useful introduction to event-driven programming, where an event triggers a function that performs a specific action. The same general approach is used in drawing applications, interface controls, and interactive games.
Connected Graphical Objects
The ball and line work together to form one visual effect. Their relationship is maintained through coordinated position updates. This teaches an important programming principle: multiple objects may need to share information to create a consistent result.
Reusable Functions
Separating the initial setup from the mouse-movement handler makes the program easier to understand. The setup function creates the objects once. The event handler updates them whenever the mouse moves. Keeping these responsibilities separate makes debugging and future modifications simpler.
Visual Feedback
The program provides immediate visual feedback when the user moves the mouse. Students can observe whether the coordinates are being read correctly and whether the objects respond as expected. This makes the exercise especially useful for beginners who are learning how programming instructions translate into visible results.
Understanding the Main Variables and Functions
The exact variable names depend on the code provided in the assignment, but the following concepts are commonly relevant.
| Element | Purpose |
|---|---|
| ball | Stores a reference to the circle object. |
| line | Stores the reference to the connecting line. |
| BALL_RADIUS | Defines the circle’s radius when a named constant is used. |
| centerX | Represents the horizontal center coordinate. |
| centerY | Represents the vertical center coordinate. |
| start() | Performs the initial setup in a typical CodeHS-style program. |
| Mouse handler | Updates the graphics in response to pointer movement. |
Understanding the Ball Variable
The ball variable stores the graphical circle so the program can reposition it later. This is important because the circle should usually be created once and updated repeatedly. Recreating it every time the mouse moves can produce unwanted visual clutter or unnecessary processing.
Understanding the Line Variable
The line variable stores the connection between the anchor point and the moving object. A line has two endpoints, so the program must know which endpoint is fixed and which endpoint changes. Using the correct endpoint-update operation prevents the line from shifting away from its intended anchor.
Understanding the Mouse Handler
The mouse handler contains the instructions that run in response to mouse movement. Its primary responsibility is to read the latest pointer coordinates and apply them to the relevant graphical objects. It should not unnecessarily repeat the initial object-creation process.
Step-by-Step Approach to Completing the Exercise
The following workflow provides a practical way to build and test the program without relying on a memorized answer.
Step 1: Read the Assignment Requirements
Identify the required graphics objects, their starting positions, and the expected behavior. Check whether the exercise specifies a particular radius, color, anchor point, or mouse interaction. These details matter because a program can behave logically but still fail to meet the exact assignment requirements.
Step 2: Declare the Necessary Variables
Create variables for the graphical objects and any important values that need to be reused. Meaningful names make the code easier to follow. If a value remains constant, a named constant can make its purpose clearer.
Step 3: Create and Position the Circle
Create the circle using the required radius, then place it at the correct initial coordinates. Check that the circle appears in the intended location and that its size matches the instructions.
Step 4: Create and Position the Line
Create the line with the correct starting and ending coordinates. If the line should originate from the center of the canvas, calculate that location using the canvas dimensions. Make sure its other endpoint corresponds to the circle’s initial position.
Step 5: Add the Objects to the Canvas
Creating a graphics object and displaying it are separate operations in many graphics libraries. Make sure both objects have been added to the canvas. If one object does not appear, check its creation, position, and canvas-addition instructions.
Step 6: Register the Mouse Event
Set up the mouse-movement handler once during initialization. The handler should receive the event information and use the latest x- and y-coordinates to update the relevant graphics.
Step 7: Update the Circle and Line Together
Whenever the mouse moves, position the circle at the pointer coordinates and update the moving endpoint of the line to the same coordinates. This keeps the visual relationship consistent.
Step 8: Test the Program
Move the pointer slowly in different directions. Confirm that the circle follows the mouse and that the line remains connected. Then move the pointer toward the canvas edges to check whether the objects continue to behave as expected.
Common Problems and How to Fix Them
The Circle Does Not Move
If the circle remains stationary, check whether the mouse handler has been registered correctly. Also confirm that the handler uses the event’s current coordinates and that it updates the existing circle object rather than an unrelated variable.
The Line Does Not Follow the Circle
This problem usually indicates that the line’s endpoint is not being updated correctly. Check whether the endpoint-update operation receives the current mouse coordinates. Confirm that the fixed endpoint remains in the intended position.
The Circle Appears in the Wrong Position
Incorrect coordinates or a misunderstanding of the canvas coordinate system can cause the circle to appear in an unexpected location. Remember that a circle’s position is generally based on its center. Do not automatically subtract the radius from the mouse coordinates unless the assignment specifically requires an offset.
The Line Appears Detached
A detached line may result from using different coordinates for the circle and the line’s moving endpoint. Use the same event coordinates for both updates. If the line is supposed to connect to the center of the circle, make sure the coordinates represent the circle’s center rather than its outer edge.
Objects Appear Multiple Times
Repeatedly creating new circles or lines inside the mouse handler can cause the canvas to accumulate graphical objects. The more efficient approach is to create the objects during setup and update their existing positions during mouse events.
The Program Produces an Error
Review the code for misspelled variable names, missing parentheses, mismatched braces, and incorrect method names. JavaScript is case-sensitive, so names that differ only in capitalization may refer to different variables. Testing each part of the program separately makes these errors easier to locate.
Best Practices for Better Results
Students can make the 9.7.4 leash exercise easier to complete by following a few simple programming habits.
- Keep setup separate from interaction. Create the graphics objects during initialization and update them inside the event handler.
- Use meaningful names. Names such as ball and line are easier to understand than unexplained single-letter variables.
- Avoid unnecessary object creation. Reuse existing graphical objects whenever the assignment calls for moving them.
- Test incrementally. Verify the circle first, then the line, and finally the interactive behavior.
- Check coordinates carefully. Ensure that the line and circle use matching endpoint and position values.
- Follow the assignment specifications. Avoid adding features that change the expected output before the required behavior works correctly.
These habits help students write clearer programs and develop debugging skills that remain useful in more advanced projects.
Learning Benefits and Practical Applications
The concepts introduced by the leash exercise extend beyond a single classroom activity.
Graphics and Animation
The exercise demonstrates how a graphical object can change position in response to input. Similar techniques are used to animate characters, move game objects, and create visual demonstrations.
Interactive User Interfaces
Mouse events are important in interfaces that respond to pointer movement, clicking, and dragging. Understanding how events deliver coordinates provides a foundation for building interactive controls.
Geometry and Spatial Reasoning
The relationship between a fixed point and a moving point introduces basic coordinate geometry. More advanced projects can use the same coordinates to calculate distances, directions, and angles.
Problem-Solving and Debugging
Because the project has a visible result, students can compare what the program should do with what actually happens. This encourages systematic testing instead of changing code randomly.
Preparation for More Advanced Projects
Once students understand how to create, position, and update graphical objects, they can apply those skills to drawing tools, simple games, interactive diagrams, and other event-driven programs.
History and Latest Updates
The 9.7.4 leash keyword is associated with a numbered programming exercise rather than a widely documented software release or a physical product model. The underlying techniques—variables, graphical objects, coordinate-based positioning, and mouse-event handlers—are established features of beginner-level JavaScript graphics programming.
The precise wording and requirements of an individual exercise can change when a course is revised. As of October 2026, the available information does not establish a specific official release date, version history, or confirmed update for the exercise itself. It would therefore be inaccurate to assign it a particular launch date or claim that a recent update introduced a specific feature.
For the most reliable interpretation of the task, students should prioritize the instructions and starter code supplied with their own assignment. Those materials determine the expected behavior and any course-specific requirements.
Frequently Asked Questions
What is 9.7.4 leash?
It is a keyword associated with a beginner programming exercise involving a circle and a line that behaves like a leash. The commonly described task uses mouse input to move the circle and update the line.
What programming language does the exercise use?
The commonly described version uses JavaScript-style syntax and a graphics library. The exact environment should be confirmed from the course in which the exercise appears.
What is the purpose of the leash line?
The line visually connects a fixed anchor point to the moving circle. Its endpoint must be updated as the circle moves so that the connection remains intact.
Why are mouse coordinates important?
Mouse coordinates tell the program where the pointer is located. The program uses the x- and y-values to determine the circle’s position and the line’s moving endpoint.
Why should the circle and line be created only once?
Creating the objects once and updating them repeatedly prevents unnecessary duplication and keeps the program easier to maintain.
What should I check if the exercise does not work?
Start by checking object creation, initial coordinates, canvas addition, mouse-handler registration, and endpoint updates. Then review the code for syntax errors and inconsistent variable names.
Can the exercise be expanded?
Yes. Once the required behavior works, students can experiment with colors, line thickness, alternative anchor points, or additional visual effects, provided these changes do not conflict with the assignment requirements.
Is 9.7.4 leash a physical dog-leash standard?
The programming context discussed here concerns a graphical leash effect, not a verified dog-leash product specification or animal-handling regulation. The numbered keyword alone should not be treated as evidence of a physical safety standard.
Conclusion
The 9.7.4 leash exercise provides a practical introduction to interactive graphics programming. Its central concept is straightforward: create a circle, draw a connecting line, and update their positions in response to mouse movement.
The exercise helps students develop an understanding of variables, coordinates, functions, event handling, and graphical object manipulation. It also encourages useful habits such as testing incrementally, reusing existing objects, and debugging one problem at a time.
By understanding the logic behind the visual effect instead of simply memorizing a solution, students can apply the same programming techniques to more complex animations, interactive applications, and beginner game projects.









