9.7.4 leash: The CodeHS JavaScript Exercise Where a Drawn Dog Follows Your Mouse, Its Distance Logic and Its Classic Bugs
Introduction
Some search terms look like riddles until someone explains the world they come from, and the 9.7.4 leash is a perfect example of one. Read it as a shopper and it sounds like the size of a surfboard cord or a dog lead measured in some code nobody uses, yet no surf shop on earth sells a leash by that name. Read it as a student and it makes instant sense, because the 9.7.4 leash is a programming exercise on CodeHS, the coding platform used in school computer science classes, and every term a fresh wave of students searches for it by its exact number and name.
The number is the address of the exercise inside the course, and the word is the picture the exercise asks the student to draw. In the 9.7.4 leash, a circle on the screen plays the part of a dog, the student’s mouse plays the part of the hand holding the lead, and a line drawn between the two plays the part of the leash itself. The dog is not free to wander wherever it likes, because the whole point of the 9.7.4 leash is that the dog follows the hand the way a real dog follows its owner, moving only when the distance between them grows longer than the leash allows.
This article explains the 9.7.4 leash honestly and completely, using what can actually be checked: the exercise’s own well-documented shape, the student discussions and explainer pages that describe it, and the ordinary JavaScript graphics ideas it is built from. It explains the logic, the distance maths and the mistakes that make the picture fall apart, and it also says plainly where the public record runs out, because CodeHS keeps its official materials behind its own classroom walls and no honest writer can quote a marking scheme that was never published.
What the 9.7.4 leash Exercise Actually Is
The 9.7.4 leash is one small exercise inside the JavaScript and graphics curriculum on CodeHS, the platform where many school students write their first real programs. CodeHS numbers its material in a steady pattern of unit, lesson and exercise, so the label simply means the fourth exercise of lesson seven in unit nine of the course the student happens to be taking. Students almost always search for the exercise by that full label, which is why the 9.7.4 leash travels around the internet as a number first and a name second.
The task itself is a drawing that moves. The student writes JavaScript that places a circle on the canvas to stand for a dog, follows the position of the mouse as the hand that holds the lead, and draws a line between dog and hand that stands for the leash connecting them. When the mouse moves away, the dog is supposed to follow, and when the mouse stays close, the dog is supposed to rest, and keeping that behaviour smooth and believable is the entire challenge that the 9.7.4 leash sets.
What makes the 9.7.4 leash more than a drawing exercise is the rule hidden inside the picture. A follower that simply jumps to the mouse every time it moves is not on a leash at all, so the program has to measure the gap between the two points again and again and decide, from that measurement, whether the dog should move and how far. That quiet decision, repeated many times a second, is what students are really being taught when their teacher assigns the 9.7.4 leash.
The Picture Behind the 9.7.4 leash
Every account of the 9.7.4 leash describes the same little scene, even though the wording of the exercise varies a little between course editions and classrooms. There is a dog, drawn as a filled circle, and there is a hand, also drawn as a circle or simply marked by the mouse position itself, and between them stretches the line that gives the exercise its name. Student code shared in homework forums even refers to a routine for redrawing that line, which tells you how central the line is: remove it, and the 9.7.4 leash becomes two dots chasing each other for no visible reason.
The scene works because it borrows its rules from real life so completely that a student can judge the result by eye. On a real walk, a dog on a lead has freedom inside a circle whose radius is the length of the lead, and it only has to move when its owner steps outside that circle. The 9.7.4 leash copies that arrangement exactly, turning an everyday experience into a rule a program can check: inside the allowed distance, nothing happens, and beyond it, the dog closes the gap until the line is slack again.
That borrowed realism is also what makes the 9.7.4 leash satisfying when it finally works. The dog does not glide like a ghost glued to the pointer, and it does not teleport in ugly jumps when the code is written well. It trots behind the hand, settles when the hand settles, and swings around corners the way a pet does, and the small gap between the living behaviour and the simple maths producing it is the first taste many students get of how animation actually works.
The Distance Maths at the Heart of the 9.7.4 leash
Underneath the picture, the 9.7.4 leash is an exercise about one measurement: the straight-line distance between two points on a grid. The dog has coordinates, the hand has coordinates, and the program finds the gap between them with the distance rule every student meets in maths class, squaring the horizontal difference and the vertical difference, adding them and taking the square root. That single number decides everything in the 9.7.4 leash, because it is compared, over and over, against the fixed length the leash is allowed to reach.
The comparison is where the behaviour comes from, and it is worth following slowly. When the measured distance is shorter than the leash length, the correct action in the 9.7.4 leash is no action at all, because a dog with slack in its lead stays where it is. When the distance grows longer than the leash length, the dog must move, and it must move in the direction of the hand rather than in some rough guess of a direction, which is why many solutions work out the angle between the two points as well as the gap.
The angle is the part of the 9.7.4 leash that student discussions complain about most, because the trigonometry function that returns it is rarely explained as patiently as the rest of the lesson. Student posts swap hints about using the arctangent of the vertical difference over the horizontal difference to find the direction, then stepping the dog a small amount along that direction until the distance is back within the limit. Whether a classroom’s version uses the angle openly or hides the same idea in simpler steps, the destination is identical: the dog ends each update exactly a leash length or less from the hand, never closer than it needs to be and never left behind.
How the 9.7.4 leash Keeps Moving
A still drawing would need none of this, so the second engine inside the 9.7.4 leash is the machinery that keeps the picture alive. CodeHS graphics programs react to events, and the event that matters here is the mouse moving, because every movement of the mouse is news that the hand has gone somewhere new. Student code for the 9.7.4 leash therefore listens for mouse movement, reads the pointer’s fresh coordinates from the event, and runs the measuring and moving logic in response, so the dog’s world updates at the speed of the student’s own hand.
Some versions of the work lean on a timer as well as on events, checking the scene again and again at short intervals whether or not anything has changed. The timer approach suits the 9.7.4 leash because a leash is a standing rule rather than a one-off reaction: the dog should keep drifting toward the hand for as long as it is out of range, including the moments just after a fast flick of the mouse stops. Either way, the shape of the solution is the same loop of sense, measure, decide and move, and students who can see that loop clearly usually find the rest of the exercise falls into place.
The redrawing matters as much as the moving, and it is the step beginners most often forget. A line on a graphics canvas does not stretch by itself, so every update of the 9.7.4 leash has to deal with the old line as well as the dog, removing it or redrawing it between the new positions of hand and dog. Readers who work through beginner programming guides and explainers will recognise the pattern from every animation they have ever met: the picture is rebuilt constantly, and the smoothness is an illusion created by rebuilding it fast.
The 9.7.4 leash in Checked Facts
The table below gathers what can honestly be stated about the 9.7.4 leash from the public record around it, meaning the descriptions published by students and explainer sites that have worked through the exercise in the open. Details that live only inside CodeHS’s own classroom materials, such as the exact starter code a particular teacher issued this term, cannot be checked from outside and have been left out rather than guessed at.
| Detail | Verified information |
|---|---|
| What the name refers to | Exercise 9.7.4, titled Leash, in the CodeHS JavaScript and graphics curriculum |
| What the program draws | A circle for a dog, the mouse as the hand holding the lead, and a line between them as the leash |
| Core rule | The dog follows the hand but only moves when the distance between them exceeds the leash length |
| Central maths | The distance formula between two coordinate points, compared against a fixed leash length; angle calculations appear in many student solutions |
| Events used | Mouse movement events, with timers used in some versions for continuous checking |
| Skills it practises | Coordinate tracking, conditional logic, event handling and incremental animation |
| Official answer key | None published openly by CodeHS; official materials sit behind classroom access |
Two rows of that table explain most of the traffic this odd little search term receives. The first is the core rule, because a student who has understood everything except the rule still has a program that misbehaves in ways that look random. The second is the answer key row, because the absence of any official public solution is exactly what sends students searching for the 9.7.4 leash in the first place, and it is why the pages they find are explanations and discussions rather than anything published by the platform itself.
The Bugs That Bite in the 9.7.4 leash
Ask a room of students what went wrong in their 9.7.4 leash and the same failures surface again and again, which is reassuring in its own way: the exercise has a known set of traps, and falling into one is a stage of the work rather than a personal failing. The commonest trap is a dog that never moves at all, which usually means the event listener was never properly connected, or the measuring code runs once at the start and is never called again when the mouse travels. The second commonest is the opposite, a dog glued permanently to the pointer, which means the distance check was skipped or written so loosely that it never once tells the dog to stay put.
The visual bugs in the 9.7.4 leash are just as traditional. Lines that smear across the canvas in a spiderweb mean the old line is not being removed or the line is being drawn to a stale pair of coordinates, a complaint so common that students describe the broken result as a web almost word for word across different forums. A dog that jitters in place usually means it is being moved by the full remaining distance and then pushed back in the same update, while a dog that drifts slowly away from the hand usually means a sign has been flipped somewhere in the subtraction, so the poor animal walks in exactly the wrong direction with complete confidence.
Debugging the 9.7.4 leash is therefore a methodical business rather than a mysterious one. Students are advised by every explainer on the subject to test one direction of movement at a time, to print or display the measured distance so the invisible decision becomes visible, and to check the line’s endpoints against the dog’s true centre rather than its edge. Readers comparing approaches across coding homework help and study notes will find the same advice everywhere, because the faults are in the logic of the scene and not in any student’s particular talent, and logic can be inspected one honest step at a time.
What the 9.7.4 leash Is Really Teaching
It would be easy to mistake the 9.7.4 leash for a lesson about drawing, but the drawing is only the excuse. The exercise is really a first meeting with the way interactive programs think, in which nothing on the screen is alive and everything that seems alive is a rule being checked very quickly. Coordinates, a measured distance, a comparison and a small step in the right direction are the whole trick, and once a student has assembled those four pieces inside the 9.7.4 leash, they own a pattern that turns up everywhere in software.
The pattern’s afterlife is easy to trace once you know to look for it. The companion who follows the hero around a game world is the dog of the 9.7.4 leash wearing better clothes, obeying the same rule about keeping a set distance and closing the gap only when it grows too wide. Camera systems that trail a character, pets in sandbox games, and even the gentle pull of a magnetised pickup drifting toward a player all reuse the same sense, measure, decide and move loop, which is why teachers keep setting the exercise long after its little dog has become famous among students.
That is also the honest answer to the question students ask while they search, which is why their teacher will not simply hand them the finished code. A copied 9.7.4 leash passes an afternoon, but the student who builds it understands events and distance in their hands rather than in their notes, and the difference shows up in every later exercise that moves anything anywhere. The exercise endures because it is small enough to finish and rich enough to matter, a combination rarer in teaching materials than it should be.
The Honest Limits of Any 9.7.4 leash Explainer
Fairness requires one section of plain limits, because pages about the 9.7.4 leash are not all written to the same standard and the differences matter to a student with a deadline. The exact wording of the exercise, its starter code and any constants a teacher expects can differ between the several CodeHS courses and editions in which a Leash exercise appears, and a student should always trust the instructions inside their own classroom over any general description, this one included. Where an explainer states a precise detail that cannot be traced to the exercise as issued, treat that detail the way this article treats the rumoured shortcuts in student folklore: as a report of what students say, not as a fact about the platform.
There is also a limit on what any outside writer can verify about the 9.7.4 leash, and it deserves to be said in the open. CodeHS sells and issues its curriculum to schools, its official solutions are not published for the open web, and teachers set their own expectations about how much help a student may take from explanations like this one. Nothing in this article is the official answer, because no official answer is available to quote, and a student who needs certainty about what their own teacher will accept should ask that teacher, whose ruling is the only one that counts at marking time.
Conclusion
In short, the 9.7.4 leash is a CodeHS JavaScript exercise in which a drawn dog follows the mouse along a drawn line, moving only when the measured distance between dog and hand grows longer than the leash allows. Its real subject is the quiet machinery beneath the picture — coordinates, the distance formula, mouse events and one small repeated decision — and the student who understands that machinery can rebuild the program, and a great many programs like it, without needing anyone’s answer key.
