Lesson goal: Slope of a line

Previous: Drawing circles with the mouse | Home | Next: Using for-loops to count

The slope of a line is most commonly quoted as the "rise over the run." More precisely, this means the $\Delta y$ over $\Delta x$, or $m=\Delta y/\Delta x$, where $m$ is commonly assigned to be the "slope." Now, do you remember how the slope works? Does a vertical line have an infinite slope or a zero slope? What about a horiztonal line? What about a $45^\circ$ line? Which lines have negative slopes?

In this lesson, you will be able to investigate these properties of the slope, by drawing any line of your choice with two mouse clicks, like was done in this lesson.

When you get the code below to work, click once, then click again to draw a line. The program will compute and tell you $\Delta y$, $\Delta x$, and the slope of your line. See if you can answer the questions posed above.

Now you try. Run this code several times, then click on two points. Try to learn properties of the slope of a line!

Type your code here:

See your results here:

This code will not run. You have to fix three things. First, the dy= line which is supposed to be $\Delta y$, which here is $y_2-y_1$. Second is the dx= line which is supposed to be $\Delta x$ which here is $x_2-x_1$. Finally, you need to fix the m= line to compute the slope of the mouse-clicked line which is $\Delta y/\Delta x$. Can you do it? Dismiss.
Show a friend, family member, or teacher what you've done!

Here is a share link to your code:

Does your code work? Want to run it on your iPhone?

Here's your code:

1. Use [Control]-[C] (Windows) or [⌘]-[C] (MacOS) to copy your code.

2. Paste it using [Control]-[V] (Windows) or [⌘]-[V] (MacOS) into this page

3. Then click the "Use on iPhone" button that you'll see.