This program counts the number of times a user clicks on the pig sprite.

  • Click Run and click on the pig. Read the error message.
  • Use a Global Variable in the event so that 1 is added to clicks and the click_count display updates each time you click on the pig.

We need to use the keyword global followed by the name of the variable that we would like to use inside of the event. We only need to use global for variables that were created earlier in the program, outside of the event.

To navigate the page using the TAB key, first press ESC to exit the code editor.

# THIS ACTIVITY IS IN PREVIEW ONLY MODE
  • Run Code
  • Submit Work
  • Next Activity
  • Show Console
  • Reset Code Editor
  • Codesters How To (opens in a new tab)