Exercise 16: Scope

Variables have a certain reach within a program. A global variable can be used anywhere in a program, but a local variable is known only in a certain area (function, loop)

Example:

In the program above, balance is a global variable. It can be used anywhere in the code. But the variable x can only be used inside addAmount.

Study drill

Try the exercises below:

1. Add a function reduce amount that changes the variable balance

After completing these continue with the next exercise.

Previous
Next

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">