A dynamic, browser-based implementation of the classic hand game. This project allows users to play against a computer, featuring customizable game lengths and persistent player personalization using Local Storage.
This is a JavaScript-driven application where players compete against a randomized computer opponent. Unlike a simple "best of 1" game, this version allows users to define the number of rounds they wish to play before the game starts, tracking the score in real-time until the limit is reached.
- Customizable Game Length: The game retrieves the number of rounds (
PlayerRounds) from Local Storage, allowing for short or marathon sessions. - Personalization: Displays the player's name dynamically, retrieved from the setup screen.
- Visual Feedback: The computer's choice is visually represented by changing images (
rock.jpeg,paper.jpg, etc.) dynamically in the DOM. - Score Tracking: Real-time updates of Player vs. Computer scores after every round.
- Session Management: Options to "Play Again" (reload) or "Quit" (return to the start screen) appear automatically when the match ends.
- Setup: (On the index page) Enter your Name and the number of Rounds you want to play.
- Make your Move: Click on Rock, Paper, or Scissors.
- The Result:
- The computer randomly selects its move.
- The score updates based on standard rules:
- 🪨 beats ✂️
- ✂️ beats 📄
- 📄 beats 🪨
- Game Over: Once the round limit is reached, the game announces the winner via an alert and offers a rematch.
- Frontend: HTML5, CSS3
- Logic: Vanilla JavaScript (ES6)
- Storage: Browser LocalStorage API (for Name and Round settings)
The core logic relies on random number generation and event listeners for the three buttons. Here is how the computer makes a choice:
function computerPlay(){
let display = "";
let randomNumber = 0;
// Generates 0, 1, or 2 representing Rock, Paper, or Scissors
for( let i = 0; i <= 1; i++){
randomNumber = Math.floor(Math.random()*3);
display = `<img src = ${imageStorage[randomNumber]}>`;
}
// Updates the UI with the computer's image
imageDisplayComputer.innerHTML = display;
return randomNumber;
}- Clone the repository:
git clone https://github.com/Otormin/RockPaperScissors.git
- Navigate to the folder:
cd RockPaperScissors
- Launch:
Open the
index.htmlfile in your browser to set up your player details, which will then redirect you to the main game board.


