Self-paced

Explore our extensive collection of courses designed to help you master various subjects and skills. Whether you're a beginner or an advanced learner, there's something here for everyone.

Bootcamp

Learn live

Join us for our free workshops, webinars, and other events to learn more about our programs and get started on your journey to becoming a developer.

Upcoming live events

Learning library

For all the self-taught geeks out there, here is our content library with most of the learning materials we have produced throughout the years.

It makes sense to start learning by reading and watching videos about fundamentals and how things work.

Search from all Lessons


LoginGet Started

Register to 4Geeks

← Back to Projects

Build a Memory Game with React: Find the Pairs!

Difficulty

  • intermediate

Average duration

4 hrs

Technologies

Difficulty

  • intermediate

Average duration

4 hrs

Technologies

🌱 How to start this project?

Do not clone this repository because we will use a different template.

We recommend opening the React template using a provisioning tool like Codespaces (recommended) or Gitpod. Alternatively, you can clone the GitHub repository on your local computer using the git clone command.

This is the repository you need to open or clone:

https://github.com/4GeeksAcademy/react-hello

⚠ You will need to have Node.js installed if you do it locally, but all of that is already installed on Codespaces or Gitpod!

📝 Instructions

Step 1: Set Up the Project

Step 2: Plan the Game Structure

Step 3: Implement the Game Board

1// Example of card generation 2const cards = [ 3 { id: 1, image: 'url1', matched: false }, 4 { id: 1, image: 'url1', matched: false }, 5 // ... more cards 6];

Step 4: Manage Card State with useState

1const [cards, setCards] = useState([]); 2const [flippedCards, setFlippedCards] = useState([]); 3const [matchedCards, setMatchedCards] = useState([]);

Step 5: Implement Game Logic with useEffect

1useEffect(() => { 2 if (flippedCards.length === 2) { 3 const [firstCard, secondCard] = flippedCards; 4 if (firstCard.id === secondCard.id) { 5 setMatchedCards([...matchedCards, firstCard.id]); 6 } 7 setTimeout(() => setFlippedCards([]), 1000); 8 } 9}, [flippedCards]);

Step 6: Add Click Event Handling

1const handleCardClick = (card) => { 2 if (flippedCards.length < 2 && !flippedCards.includes(card)) { 3 setFlippedCards([...flippedCards, card]); 4 } 5};

Step 7: Add Simple Animations

1.card { 2 transition: transform 0.6s; 3 transform-style: preserve-3d; 4} 5 6.card.flipped { 7 transform: rotateY(180deg); 8}

Step 8: Improve the User Interface

Bonus Section

Additional Features to Practice and Improve the Project:

  1. Score Counter: Implement a scoring system based on the number of moves or the time it takes the player to complete the game!

  2. Difficulty Levels: Add different difficulty levels with more or fewer cards.

  3. Sounds and Effects: Add sound effects when flipping cards or finding a pair!

  4. Save Progress: Allow the player to pause and continue the game by saving the state in local storage.

  5. Customizable Theme: Let the player choose between different themes or sets of images for the cards!

  6. Multiplayer Game: Implement a mode where two players compete in turns and record who finds more pairs.

Explore different enhancements to make your memory game more interactive and entertaining!

Signup and get access to similar projects

We will use it to give you access to your account.
Already have an account? Login here.

By signing up, you agree to the Terms and conditions and Privacy policy.

Difficulty

  • intermediate

Average duration

4 hrs

Technologies

Difficulty

  • intermediate

Average duration

4 hrs

Technologies

Difficulty

  • intermediate

Average duration

4 hrs

Technologies

Difficulty

  • intermediate

Average duration

4 hrs

Technologies

Signup and get access to similar projects

We will use it to give you access to your account.
Already have an account? Login here.

By signing up, you agree to the Terms and conditions and Privacy policy.

Difficulty

  • intermediate

Average duration

4 hrs

Technologies

Difficulty

  • intermediate

Average duration

4 hrs

Technologies