9.7.4 Leash is a JavaScript graphics exercise in the CodeHS curriculum that teaches students how lines, circles, coordinates, and mouse movements work together. The activity involves creating a ball connected to a fixed point with a line. As the mouse moves, the ball follows the pointer, creating the appearance of an object attached to a leash.
Although the exercise looks simple, it introduces useful programming concepts, including graphical objects, event handling, callback functions, and coordinate positioning. Understanding these basics can help students build confidence with JavaScript and interactive graphics.
What Is 9.7.4 Leash?
9.7.4 Leash is an interactive programming exercise found in the Drawing Lines section of the CodeHS JavaScript curriculum. Students create a circle and connect it to a fixed point using a line. When the mouse moves, the circle and the line’s endpoint update to follow the pointer.
The activity demonstrates how graphical objects can respond to user actions. It is an educational programming task rather than a physical leash or commercial product.
What Does 9.7.4 Mean?
The number 9.7.4 identifies the exercise’s position within a particular CodeHS course. The first number represents the unit, the second identifies the lesson, and the third indicates the individual activity.
In the relevant JavaScript curriculum, the exercise appears under Unit 9, Lesson 9.7, Drawing Lines. Course numbering can vary between versions, so students should check their assigned course for the correct exercise.
How Does 9.7.4 Leash Work?
The exercise works by connecting two graphical elements through mouse coordinates. A circle represents the moving ball, while a line connects it to a fixed position on the canvas.
Whenever the user moves the mouse, the program receives updated X and Y coordinates. It uses those values to reposition the circle and change the line’s endpoint, maintaining the visual connection.
Main Goal of the Exercise
The main purpose of 9.7.4 Leash is to teach students how multiple graphical objects can respond to one event. The circle follows the mouse, while the line maintains its connection to the moving object.
Through this activity, students learn how shared coordinate values can control different elements. It also introduces event-driven programming, where a program responds to user interaction.
Understanding Canvas Coordinates
Coordinates determine where graphical objects appear on a screen. CodeHS uses an X-Y coordinate system, where the X value controls horizontal positioning and the Y value controls vertical positioning.
Students can use getWidth and getHeight to determine canvas dimensions. Dividing these values by two helps locate the centre, making it easier to position objects accurately.
Creating the Circle and Line
The circle represents the moving object and can be created using the CodeHS Circle constructor. Students can position it with setPosition(x, y) and display it using add.
The leash is created using the Line constructor. Its starting point remains fixed, while setEndpoint(x, y) updates its ending position as the mouse moves.
Mouse Movement and Events
Mouse interaction is an essential part of this exercise. CodeHS provides mouseMoveMethod to register a function that responds whenever the mouse moves across the graphics canvas.
This function allows the program to receive updated pointer information and change graphical objects accordingly. It introduces students to event-driven programming, which is commonly used in games, websites, and interactive applications.
Important JavaScript Functions
Several functions and methods help students complete the exercise. Each has a specific purpose, and understanding their roles makes programming easier.
| Function | Purpose |
| Circle | Creates a circle |
| Line | Draws a line |
| add | Adds an object to the canvas |
| setPosition | Changes object position |
| setEndpoint | Updates a line’s endpoint |
| getWidth | Returns canvas width |
| getHeight | Returns canvas height |
| mouseMoveMethod | Registers mouse movement |
| e.getX | Gets horizontal mouse position |
| e.getY | Gets vertical mouse position |
Common Mistakes
Students sometimes move the circle without updating the line’s endpoint. This causes the two objects to appear disconnected. Another common mistake is changing the line’s starting point instead of its endpoint.
Forgetting to register the mouse event, using incorrect capitalization, or creating new objects repeatedly can also cause problems. Checking the program one section at a time helps identify these mistakes.
Understanding Callback Functions
A callback is a function passed to another function so it can execute later when a particular event occurs. In this exercise, mouseMoveMethod registers the function that should run when the mouse moves.
Students should pass the function itself rather than calling it immediately. Understanding this difference is useful for learning JavaScript event handling and building interactive applications.
Benefits of Learning 9.7.4 Leash
The exercise helps students develop practical programming skills through visual learning. They can immediately see how their instructions affect graphical objects, making coordinates and event handling easier to understand.
It also improves logical thinking, debugging, and problem-solving. These skills provide a useful foundation for future projects involving animations, drawing applications, interactive websites, and simple games.
9.7.4 Leash vs. 4.7.4 Leash
Some students may find references to both 9.7.4 Leash and 4.7.4 Leash online. These numbers can reflect different CodeHS course structures or curriculum versions.
Students should compare the assignment instructions and expected results before assuming both exercises are identical. The official Golden curriculum identifies Leash as Exercise 9.7.4 under Drawing Lines.
Is 9.7.4 Leash a Python Exercise?
No. The exercise discussed here belongs to the CodeHS JavaScript Graphics curriculum. It involves graphical objects, mouse events, coordinates, and methods such as Circle, Line, and setEndpoint.
Other online explanations may use similar wording for different programming activities. Students should follow the language and instructions provided in their own CodeHS assignment.
Final Thoughts
9.7.4 Leash is a useful CodeHS exercise for learning JavaScript graphics and interactive programming. By connecting a moving circle to a fixed point with a line, students can understand how coordinates and mouse events work together.
The activity also introduces callback functions and real-time graphical updates. These concepts are useful for developing more advanced programming skills and understanding how interactive applications respond to users.
Must Read: Schoology Alfa Fundación: A Complete Guide for Students
FAQs
1. What is the purpose of the 9.7.4 Leash exercise?
The exercise teaches students how to create connected graphical objects and update their positions using mouse movements in JavaScript.
2. How does the circle follow the mouse in 9.7.4 Leash?
The program uses mouse coordinates to update the circle’s position whenever the pointer moves across the graphics canvas.
3. What is the role of coordinates in this exercise?
Coordinates determine where the circle and line appear. The X and Y values help maintain the connection between both graphical elements.
4. Can beginners understand the 9.7.4 Leash exercise?
Yes. Beginners can understand it by learning basic JavaScript functions, graphical objects, and mouse events before combining them in the exercise.
5. What can students learn after completing 9.7.4 Leash?
Students gain experience with interactive graphics, callback functions, event handling, and object positioning, which are useful in animation and game development.










Coldmags Com Review: What Works and What Doesn't - ezlo.co.uk
November 3, 2026[…] Must Read: What Is 9.7.4 Leash? A Simple Guide to the CodeHS Exercise […]