<< Chapter < Page Chapter >> Page >

Repetitively clicking the mouse in the Stage area causes the Counter variable to count down in increments of oneand causes the counter variable to count down in increments of five.

Event-driven programming

The ability to write programs that cause certain operations to occur in response to events (such as pressing the space bar and clicking the mouse on the Stage) is often referred to as event-driven programming.

It is easy to write event-driven programs in Scratch. On the other hand, writing event-driven programs is not so easy in languages such asJava, C#, and C++. You need quite a lot of programming knowledge to write event-driven programs in those languages.

It is useful to give programming students a taste of event-driven programming early, if for no other reason than the factthat it tends to make programming more interesting.

Example blocks with pointed ends

The blocks shown in Image 4 are not used in this program. They are shown in this module to illustrate blocks with pointed endsreferred to earlier .

Image 4. example blocks with pointed ends.

Missing image.
Image 4. Example blocks with pointed ends.

Run the program

I encourage you to use the information provided above along with the Scratch 2.0 programming interface shown in Image 1 to write and run this program. Experiment with the code, making changes, and observing the results of yourchanges. Make certain that you can explain why your changes behave as they do.

A copy of this program has been posted online for your review.

I also encourage you to write the programs described below.

Student programming projects

The following projects are designed to:

  • Help the student retain the knowledge gained by studying the module.
  • Require the student to think beyond the material presented in the module by requiring the student to answer the question "How do I ...?"

Project 1

Begin with the program named Variable01 and modify it to create a new program named Variable02 . Modify the original program in such a way that pressing the space bar five times in succession, (after clicking the green flag to set both variables to zero) , will cause the displayed values of the variables named Counter and counter to be as shown in Image 5 .

Image 5. output from project 1.

Missing image.
Image 5. Output from Project 1.

Having reached that point, clicking the mouse five times in succession in the Stage area will cause the displayed values of the variables named Counter and counter to be as shown in Image 6 .

Image 6. output from project 1.

missing image
Image 6. Output from Project 1.

A copy of this program is posted online for your review.

Project 2

You should successfully complete Project 1 before attempting this project. Begin with the program named Variable01 and modify it to create a new program named Variable03 . Modify the original program in such a way that pressing the space bar five timesin succession, (after clicking the green flag to set both variables to zero) , will cause the displayed values of the variables named Counter and counter to be as shown in Image 7 .

Image 7. output from project 2.

Missing image.
Image 7. Output from Project 2.

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Teaching beginners to code. OpenStax CNX. May 27, 2013 Download for free at http://cnx.org/content/col11498/1.20
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Teaching beginners to code' conversation and receive update notifications?

Ask