The exercises in this article give you practice in:
- Creating and using variables
- Using arithmetic operators
- Using assignment operators
- Using comparison operators
- Creating and using arrays
- Creating loops and iterating arrays
- Creating and using functions
Exercise 1: Creating variables
Variables are the building blocks for any programming language. They provide a way to store and retrieve information later in a script. For this exercise:
- Use the
varkeyword to create a variable and retrieve the variables value using the
Exercise 2: Using operators
- Use an arithmetic operator to perform a basic mathematic operation and use it as a variable value.
- Use comparison operators to determine the relationship between variables and their values.
Exercise 3: Creating an array and using a loop to iterate its values
You use arrays to store multiple values in a single variable. You can use loops to iterate arrays and access their values. For this exercise:
- Create an array and assign values to it.
- Create a for loop and use it to iterate the array.
Exercise 4: Creating functions, accepting parameters, and returning values
Functions contain script that can be used to handle a specific task. You can use functions to execute their contained script and run their tasks at any time. For this exercise:
- Structure a custom function named
- Include a function parameter named
- Increase the value of the parameter and return the new value.
Follow these solution steps to check your work.
- Stay current with developerWorks technical events and webcasts focused on a variety of IBM products and IT industry topics.
- Follow developerWorks on Twitter.