CMSC104, Fall 2010
Programming Project 2
Rock, Paper, Scissors!
Out: Monday, November 8, 2010
Due Date: Sunday, November 21, 2010 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. Notice that the words begin with capital letters. The input must match exactly. (Hint: You want to continue the error checking loop while the user choice is not equal to "Rock" AND not equal to "Paper" AND not equal to "Scissors".)
- 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. For example:switch(randomNum) { case 1: computerChoice = "Rock"; break; etc...
- 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 and continue to prompt the until yes or no is entered. You should only accept "yes" or "no" exactly, no variations.
- All output displayed to the user should be done with alerts.
- Make sure that when you use the strings "Rock", "Paper", or "Scissors" in your code you surround them in quotes.
- 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
User entering incorrect input
Error message for incorrect input
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.