Labs

Lab 5.5: Objects of Attention

Print
References

In this set of exercises, we'll spice up our code by making use of some of JavaScript's1 built-in objects2 and properties. As in the earlier labs, treat these as independent exercises that should be attempted and tested out one at a time.

  1. It is often helpful in situations where you are working on a program over an extended period of time to have an indicator that tells you which version of the program you are working on. Use JavaScript's Date class3 to display the current date and time somewhere on your game page.


  2. Let's make use of JavaScript's facility with colors to make our program a bit more colorful. Change function setMode so that every time the game's mode is changed (between Action and Look), the background color of the document changes. That is, pick a color to correspond to Action mode, and another color to represent Look mode, and set the document's background color to reflect the current mode. Note that you'll have to remove the default color assigned in the original HTML description.


  3. While our original program did not make explicit use of JavaScript arrays, any JavaScript program that works with HTML forms uses an array4 implicitly. In fact, the forms array is a property of every document, and it contains an entry for each form in the document. Forms are ordered in the array by their appearance in the document, and are referred to beginning with subscript zero. This means that in our concert game, document.forms[0] is another way to refer to form rightForm, and document.forms[1] is another name for form statusForm. Replace some occurrences of rightForm and statusForm with their forms array counterparts, and verify that your code works as did the original.


  4. Review the description in the text of JavaScript's String class so that we can use it to make our program a bit more realistic. In particular, notice that while you need ATM Cash in your inventory to purchase anything (like the jacket) at the clothing store, money is not "deducted" from your inventory when you do make a purchase. Write a function named SpendATMCash that removes "ATM Cash" from the inventory list (if it indeed is in the list to begin with). Then, change function processBeat so that it removes ATM Cash from your inventory whenever you check out at the cashier.
1pp. 126, 127, 139–196, 149
2pp. 149, 153–158, 210, 270
4pp. 189–190, 221

Labs

MODULES:


Home Search Resources Objectives Feedback Order Form Credits

Copyright Notice
© 1998 PWS Publishing Company, All Rights Reserved.