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

Sentry blog image

How I fixed 20 seconds of lag for every user in just 20 minutes.

Our AI agent was running 10-20 seconds slower than it should, impacting both our own developers and our early adopters. See how I used Sentry Profiling to fix it in record time.

Read more

Top comments (0)

nextjs tutorial video

Youtube Tutorial Series ๐Ÿ“บ

So you built a Next.js app, but you need a clear view of the entire operation flow to be able to identify performance bottlenecks before you launch. But how do you get started? Get the essentials on tracing for Next.js from @nikolovlazar in this video series ๐Ÿ‘€

Watch the Youtube series