CMSC104, Fall 2007
Programming Project 2
Rock, Paper, Scissors!
Out: Monday, November 12, 2007
Due Date: Sunday, November 25, 2007 before 11:59 p.m.
The Objective
This project is designed to give you practice with loops and switch statements. You will also get practice designing and writing your first JavaScript program from scratch.The Task
The program you write will implement the classic game of Rock, Paper, Scissors. If you are not familiar with the game, please read the Wikipedia page about the game. Your program should allow the user to play against the computer. You should keep a running total of the number of player wins, losses, draws (ties) and games played. When the user is finished playing, you should display the statistics for that run of games.
- You should error check the user input to make sure it is either Rock, Paper or Scissors. If the user types anything else, you should keep prompting him/her to enter a new value until a correct value is entered. If you would like to allow the user to enter Rock/rock, Paper/paper or Scissors/scissors, that is fine but not required.
- In order to simulate the computer playing, you need to generate a random number. The
formula to do so is:
randomNum = Math.ceil((Math.random() * 3));
The formula will generate a random number in the range 1 - 3, inclusive. You should use a switch statement to assign the computer's choice according to the following: 1 corresponds to Rock, 2 corresponds to Paper and 3 corresponds to Scissors. - You should use a do/while loop to allow the user to continue playing games until ready to quit. You should ask the user if they would like to play another game and allow them to answer yes or no. You should error check to make sure the user types either yes or no. You should continue to prompt the user until yes or no is entered.
- All output displayed to the user should be done with alerts.
- I used the following sayings but you may choose your own if you'd like:
- "Scissors cut Paper!"
- "Paper covers Rock!"
- "Rock crushes Scissors!"
Screenshots
Welcome screen
Get ready screen
Getting the input
Showing the computer's guess
Displaying the results
Asking to play again - yes
Getting another input
Showing the computer's guess
Displaying the results
Asking to play again - no
Displaying the statistics
Submitting the Program
You do not have to do anything to submit the program. It should be in your pub/www/cs104/proj2 directory.