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
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
- 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.
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.
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.
Learn how to create Events,
Stay current with developerWorks
technical events and webcasts focused on a variety of IBM products and IT
Follow developerWorks on Twitter.
Kris Hadlock has been a contract web developer and designer since 1996. He has worked on projects for companies such as SPIN Magazine, IKEA, United Airlines, JP Morgan Chase, GoDaddy Software, and Fire Mountain Gems. He is the author of Ajax for Web Application Developers (Sams) and The ActionScript Migration Guide (New Riders) as well as a featured columnist and writer for numerous websites and design magazines, including Peachpit.com, InformIT.com, and Practical Web Design magazine. Kris is also the founder of www.studiosedition.com, a web design and software development studio specializing in fusion of form and function.