Coder Social home page Coder Social logo

memory-card's Introduction

This is a memory card game created using React, JavaScript, HTML & CSS.

Live site URL: itsaflamingo.github.io/memory-card

Link to assignment: https://www.theodinproject.com/lessons/node-path-javascript-memory-card

My Image

How the game flows:

  • Rules:
    • pictures will be randomized after every state change
    • game will reset if picture is clicked twice onClick =>
  1. check if picture has been clicked by checking whether classList includes 'clicked'
  2. If it does, set score to 0 & determine whether this is a new best score by comparing with the previous best score
  3. If it doesn't, add 1 to score and add class of 'clicked' to div

How the game is structured:

App.js: This is the main page of the code, where I add all components. It's also where I save state, because it is the parent of the two components that both utilize the state (Head & Main), and therefore need access to it. I decided to store the pictures as nested objects within an array, because it would allow me to easily display each object by accessing its url key and the name of the character, by accessing the name key. The array allows me to forgo naming each object, and to use the map function to iterate over each array element and return the picture.

Head.js: This displays the score, which I pass as props from App.js. The score is updated whenever a picture is clicked, and bestScore is updated when a picture is clicked twice.

Main.js: This displays the picture and name of each object within my pictures array. I pass the props to Card.js using spread syntax for simplicity. Main.js just serves as a container for all the cards.

Card.js: I map over the pictures array, returning each picture as a div background & displaying the name underneath, and adding the onClick event handler to each parent div.

memory-card's People

Contributors

itsaflamingo avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.