Objective
To practice functions, forms, and event handling.
Overview
For this project you will write a guessing number game. The program will
generate a random value in a range of values specified by the user, and will
process the user guesses. You do not need to provide pseudocode for this
project, but you are encourage to develop it for your own benefit.
The following files are associated with this project: Proj3.zip.
Specifications
You must define a form with the text fields and buttons you can see in the
Sample Run. The text areas will allow the user to specify the upper and lower
limits associated with the range of values from which your program will
select a random value. The "PlayGame" button will start the game (your
program will choose a random value and start asking the user for guesses).
The "ResetValues" button will restore the default values associated with the
limits. The following provides additional information regarding the
functionality of the program.
- The default values of the lower and upper limits are one and three,
respectively.
- The upper and lower limit values can be selected as numbers to be
guessed.
- The program will generate a random value (target value) the user needs
to guess.
- After generating the target random value the program will ask the user
for a guess (using the dialog box you see in the Sample Run). If the
guess is correct, the program will create a pop-up window with the
"congratulations.html" file. Otherwise, the program will ask the user
whether he/she wants to continue playing (see Sample Run for the dialog
box to use). The program will keep asking the user for guesses (and
comparing against the target value) as long as the user wants to keep
playing. If the user decides to stop playing, the program will display
the expected guess (target value) and will end. Notice the
program will not create a new target value each time the user fails to
provide a correct answer.
- You must define and use the following functions:
- playGame - This function has no parameters. This
function generates the random value, ask the user for guesses, and
processes the responses.
- getRandomValue - This function has two parameters
that represent the lower and upper limits, respectively. The function
will return a random value in the specified range. You must use the
Math.random() function to compute the random value.
- main - You must have a main function whose only
task is to associate the "PlayGame" button with the playGame
function.
Requirements
- You must name your file p3.html.
- You must use good identation.
- You must use meaningful variable names.
- You may not use global variables
- You may not add functions besides the ones specified above.
- You may not modify the congratulations.html file.
- Your code must validate according to http://validator.w3.org/#validate-by-upload.
Sample Run
The application video
illustrates the functionality associated with the program.