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
๐ ๏ธ How to Run the Project
-
Create the Files:
- Create a folder called
rock-paper-scissors
. - Inside this folder, create three files:
index.html
,styles.css
, andscript.js
.
- Create a folder called
-
Copy the Code:
- Paste the HTML, CSS, and JavaScript code into the respective files.
-
Open the HTML File:
- Open
index.html
in your browser to play the game.
- Open
๐ How the Game Works
-
Select a Choice:
- Click on one of the buttons: Rock ๐ชจ, Paper ๐, or Scissors โ๏ธ.
-
Computer's Choice:
- The computer randomly selects Rock, Paper, or Scissors.
-
Display the Results:
- The game shows your choice, the computer's choice, and who wins.
-
Play Again:
- Click the "Play Again" button to reset the game.
๐ง Key Concepts for Learning
JavaScript Concepts
-
Event Listeners:
- Use of
addEventListener
to handle button clicks.
- Use of
-
Random Number Generation:
-
Math.random()
to generate a random choice for the computer.
-
-
Conditionals:
-
if-else
statements to determine the winner.
-
-
DOM Manipulation:
- Dynamically updating the HTML content using
textContent
.
- Dynamically updating the HTML content using
Top comments (0)