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)