In this set of exercises we continue our efforts to expand our concert game by making changes to the JavaScript1 code at the function2 level. Each of the following exercises asks you to define and invoke a function of your own. As before, you should make changes to your version of the code to accomplish the proposed changes, and then test your changes out by loading your file into your browser3 and testing it out
-
There are two different places in the original program
where we use the following statement to clear the inventory list:
document.rightForm.inventoryList.value = ""
Write a function named clearInventory
to accomplish this processing. Then, replace the occurrences of the statement with calls to your new function.
-
There are five different places in our original program
where the following lines of code are repeated exactly:
SetMode ("Look")
SetImage (mapImg)
document.statusForm.statusList.value =
"Gettin' ready for the show..."
Write a function named returnToMap that
encapsulates these statements. Then, replace each group of the three statements with a call to function returnToMap.
-
Throughout the JavaScript code, status window text
is displayed below the current image using statements like:
document.statusForm.statusList.value =
"whatever string is to be displayed"
Write a function named setStatus that
accomplishes this operation, and replace all of the statements like the
one above with calls to setStatus, like
setStatus ("whatever
string is to be displayed")
Use function setImage as a model.
-
Write three functions named clickedOnHair,
clickedOnHat, and clickedOnNail, which will return true
or false to indicate whether or not you have clicked on the respective
articles while at the clothing store. Use your browser's status bar to
help you determine the appropriate coordinate range for each article within
the clothing store image. Add these functions to the script tag that contains
all of the other clickedOn... functions.
-
In the course of playing the game you have probably noticed that an individual item (say, the jacket at the clothing store) can get added to your inventory many times. In fact, if you click on an item repeatedly when in Action mode, that article will be added to your inventory once for each click. Modify functionaddToInventory so that it precludes this behavior. That is, if an article already appears in the inventory list when it is clicked on, an alert should be displayed indicating that the item has already been purchased and it should not be added to the inventory again.
-
Now, change function processBeat so that
it uses your new clickedOn... functions (from exercise 4) to recognize clicks on the hair, hat and nail polish. When any of these is clicked, whether in Look or Action mode, an alert box should be displayed
indicating that service is currently unavailable.
|
1pp. 126, 127, 139–196, 149 2pp. 144–146, 179-182, 239–240 3pp. 9, 14–15, 70–71, 143, 146
|