1. Home
  2. Computing & Technology
  3. JavaScript

Points Distribution Script

1. What it Does

With some games you want the player to be able to choose between a number of different options. Each of these options has a 'cost' in points so that they can slect more than one option provided that the number of points required for the selected options does not exceed the points available. This script will display the number of points that remain available as the various options are selected and stop options being selected if the required points exceeds the number remining.

To start with let's look at an example of how the script works. In this example there are fifty points available and four options. As you select the options the number of points remaining will be reduced accordingly. If you attempt to select an option that exceeds the number remaining an 'insufficient points' alert will be displayed and the option will be unchecked.

Points remaining:
Option One (cost 5)
Option Two (cost 15)
Option Three (cost 35)
Option Four (cost 30)

Next we will look at the coding of the script and how to add the script to your page.

What it Does | Adding the Script | Calling the Script
Explore JavaScript
About.com Special Features

Holiday Central

What to eat, where to go, fun things to do and how to save money on the perfect gifts. More >

Family Tech Center

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

  1. Home
  2. Computing & Technology
  3. JavaScript

©2009 About.com, a part of The New York Times Company.

All rights reserved.