DEV Community

Cover image for Rock, Paper, Scissors (with JavaScript)
TD!
TD!

Posted on

3

Rock, Paper, Scissors (with JavaScript)

This project is perfect for intermediate learners because it blends HTML, CSS, and JavaScript to create a complete, functional game.


📂 File Structure

rock-paper-scissors/
│-- index.html    ← HTML structure
│-- styles.css    ← CSS styling
└-- script.js     ← JavaScript functionality
Enter fullscreen mode Exit fullscreen mode

🛠️ How to Run the Project

  1. Create the Files:

    • Create a folder called rock-paper-scissors.
    • Inside this folder, create three files: index.html, styles.css, and script.js.
  2. Copy the Code:

    • Paste the HTML, CSS, and JavaScript code into the respective files.
  3. Open the HTML File:

    • Open index.html in your browser to play the game.

🌟 How the Game Works

  1. Select a Choice:

    • Click on one of the buttons: Rock 🪨, Paper 📄, or Scissors ✂️.
  2. Computer's Choice:

    • The computer randomly selects Rock, Paper, or Scissors.
  3. Display the Results:

    • The game shows your choice, the computer's choice, and who wins.
  4. Play Again:

    • Click the "Play Again" button to reset the game.

🧠 Key Concepts for Learning

JavaScript Concepts

  1. Event Listeners:

    • Use of addEventListener to handle button clicks.
  2. Random Number Generation:

    • Math.random() to generate a random choice for the computer.
  3. Conditionals:

    • if-else statements to determine the winner.
  4. DOM Manipulation:

    • Dynamically updating the HTML content using textContent.

View on GitHub

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

Top comments (0)

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

👋 Kindness is contagious

Discover a treasure trove of wisdom within this insightful piece, highly respected in the nurturing DEV Community enviroment. Developers, whether novice or expert, are encouraged to participate and add to our shared knowledge basin.

A simple "thank you" can illuminate someone's day. Express your appreciation in the comments section!

On DEV, sharing ideas smoothens our journey and strengthens our community ties. Learn something useful? Offering a quick thanks to the author is deeply appreciated.

Okay