Rock Paper Scissors Game

Interactive Rock Paper Scissors battle with animated shake countdown, score history, streaks, and computer AI logic.

Difficulty: Beginner Est. Time: 20 mins Vanilla JS (ES6+) Includes HTML, CSS, JS & README (.ZIP)
Live UI Runner

Rock Paper Scissors Game

live-sandbox://rock-paper-scissors

1. Project Overview & Features

The Rock Paper Scissors Game is an essential frontend project designed to help you bridge the gap between learning JavaScript syntax and building interactive, responsive web applications.

Key Features Implemented:

  • Animated player and computer battle showdown
  • Interactive choice buttons (Rock, Paper, Scissors)
  • Live round scoreboard and winning streak counter
  • Play again reset action

2. Step-by-Step Code Walkthrough

A Step 1: Semantic HTML Structure

We structure the interface using clean, semantic HTML elements. This ensures maximum accessibility and provides intuitive hooks for CSS classes and JavaScript query selectors.

HTML (index.html)
<div class="rps-card">
  <div class="rps-scoreboard">
    <div class="score-item">
      <span>PLAYER</span>
      <h3 id="p-score">0</h3>
    </div>
    <div class="score-item">
      <span>STREAK</span>
      <h3 id="streak-score" style="color:#eab308">0</h3>
    </div>
    <div class="score-item">
      <span>COMPUTER</span>
      <h3 id="c-score">0</h3>
    </div>
  </div>

  <div class="arena">
    <div class="fighter" id="p-fighter"><i class="fas fa-hand-rock"></i></div>
    <div class="vs">VS</div>
    <div class="fighter" id="c-fighter"><i class="fas fa-hand-rock"></i></div>
  </div>

  <h2 id="result-msg" class="result-msg">Choose your weapon!</h2>

  <div class="choices-row">
    <button class="choice-btn" data-choice="rock">✊ Rock</button>
    <button class="choice-btn" data-choice="paper">βœ‹ Paper</button>
    <button class="choice-btn" data-choice="scissors">✌️ Scissors</button>
  </div>
</div>

B Step 2: Styling & Responsive CSS

Modern CSS flexbox and grid layouts are used to make the UI look polished, centered, and responsive across desktop, tablet, and mobile screens.

CSS (style.css)
* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}
body {
  background: #0f172a;
  color: #f8fafc;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.rps-card {
  background: #1e293b;
  border: 1px solid #334155;
  border-radius: 24px;
  padding: 28px;
  width: 100%;
  max-width: 440px;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
  text-align: center;
}
.rps-scoreboard {
  display: flex;
  justify-content: space-around;
  background: #0f172a;
  padding: 12px;
  border-radius: 14px;
  margin-bottom: 24px;
  border: 1px solid #334155;
}
.score-item span {
  font-size: 0.7rem;
  color: #94a3b8;
  font-weight: 700;
}
.score-item h3 {
  font-size: 1.5rem;
  font-weight: 800;
}
.arena {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 32px;
  margin-bottom: 24px;
  height: 120px;
}
.fighter {
  font-size: 4rem;
  color: #38bdf8;
  transition: transform 0.2s;
}
#c-fighter {
  color: #f43f5e;
  transform: scaleX(-1);
}
.vs {
  font-weight: 900;
  color: #64748b;
  font-size: 1.2rem;
}
.result-msg {
  font-size: 1.25rem;
  margin-bottom: 24px;
  min-height: 32px;
}
.choices-row {
  display: flex;
  gap: 10px;
}
.choice-btn {
  flex: 1;
  background: #334155;
  color: #f8fafc;
  border: 1px solid #475569;
  padding: 14px 8px;
  border-radius: 12px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
}
.choice-btn:hover {
  background: #0284c7;
  border-color: #38bdf8;
}

C Step 3: JavaScript Logic & Event Handling

Here is the complete JavaScript code handling the state, event listeners, mathematical logic, and dynamic DOM rendering:

JavaScript (script.js)
let pScore = 0;
let cScore = 0;
let streak = 0;

const pFighter = document.getElementById('p-fighter');
const cFighter = document.getElementById('c-fighter');
const resultMsg = document.getElementById('result-msg');
const pScoreEl = document.getElementById('p-score');
const cScoreEl = document.getElementById('c-score');
const streakEl = document.getElementById('streak-score');

const icons = {
  rock: 'fa-hand-rock',
  paper: 'fa-hand-paper',
  scissors: 'fa-hand-scissors'
};

document.querySelectorAll('.choice-btn').forEach(btn => {
  btn.addEventListener('click', () => {
    const playerChoice = btn.dataset.choice;
    playRound(playerChoice);
  });
});

function playRound(playerChoice) {
  const choices = ['rock', 'paper', 'scissors'];
  const computerChoice = choices[Math.floor(Math.random() * 3)];

  pFighter.innerHTML = `<i class="fas ${icons[playerChoice]}"></i>`;
  cFighter.innerHTML = `<i class="fas ${icons[computerChoice]}"></i>`;

  if (playerChoice === computerChoice) {
    resultMsg.textContent = "It's a Tie! 🀝";
    resultMsg.style.color = '#facc15';
  } else if (
    (playerChoice === 'rock' && computerChoice === 'scissors') ||
    (playerChoice === 'paper' && computerChoice === 'rock') ||
    (playerChoice === 'scissors' && computerChoice === 'paper')
  ) {
    resultMsg.textContent = "You Win! πŸŽ‰";
    resultMsg.style.color = '#10b981';
    pScore++;
    streak++;
  } else {
    resultMsg.textContent = "Computer Wins! πŸ’»";
    resultMsg.style.color = '#ef4444';
    cScore++;
    streak = 0;
  }

  pScoreEl.textContent = pScore;
  cScoreEl.textContent = cScore;
  streakEl.textContent = streak;
}

3. Core JavaScript Concepts You Learned

Math.random() Decisions

Crucial concept utilized to power the dynamic state, user interactions, and styling of this project.

Conditional Win/Loss Logic

Crucial concept utilized to power the dynamic state, user interactions, and styling of this project.

CSS Keyframe Triggers

Crucial concept utilized to power the dynamic state, user interactions, and styling of this project.

State Streaks

Crucial concept utilized to power the dynamic state, user interactions, and styling of this project.

4. How to Run Locally on Your Computer

  1. Download the project ZIP: Click the Download Project (.ZIP) button at the top or in the live runner to save rock-paper-scissors-project.zip.
  2. Extract the archive: Unzip the downloaded file. Inside you will find separate index.html, style.css, script.js, index-standalone.html, and a comprehensive README.md.
  3. Open in any browser: Simply double-click index.html (or index-standalone.html) to open and test immediately in Chrome, Firefox, Safari, or Edge.
  4. Edit in Visual Studio Code: Open the extracted folder in VS Code. Right-click index.html and select "Open with Live Server" to enjoy instant live reloading as you modify HTML, CSS, or JS!

Bonus Challenges for Learners

Ready to level up? Try adding these extra features on your own:

  • Add sound effects or audio feedback for user button clicks.
  • Add custom theme color customizer with CSS variables.
  • Export the results to PDF or copy as a formatted text summary.

Other Beginner Projects You Might Like

Beginner25 mins
Games

Tic-Tac-Toe Game with AI Mode

Classic 3x3 Tic-Tac-Toe game supporting 2-Player local mode and Single Player vs smart AI with winning combination highlights and streaks.

2D Array Grid RepresentationWinning Line AlgorithmsGame State Management+1
Beginner30 mins
Games

Memory Card Matching Game

A 4x4 card flipping memory game with 3D flip animations, move counters, timer, match pair checks, and celebration popups.

Fisher-Yates ShuffleCSS 3D perspective & rotateYsetTimeout Board Lock+1