Lesson goal: The while-loop and mouse clicks

Previous: Average some numbers | Home | Next: You guess my number

Here's a use of the while-loop that waits (with a while loop) for you to click inside of the circle drawn on the screen. It computes the distance of your mouse click to the origin to see if you are inside of the circle of radius 20 pixels. Note the logic...setting the variable called done to false, to "prime" the while-loop. The while-loop executes over and over while the done variable is false.

Now you try. Fix the d= line to be the distance of your mouse click to the origin, and the if statement to see if this distance is $\le 20$ (the radius of the circle).

Type your code here:

See your results here: