-
-
Notifications
You must be signed in to change notification settings - Fork 81
Memory – Pair Game #445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Memory – Pair Game #445
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <title>Memory Pairs Game</title> | ||
| <link rel="stylesheet" href="style.css"> | ||
| <link rel="preconnect" href="https://fonts.gstatic.com"> | ||
| <link | ||
| href="https://fonts.googleapis.com/css2?family=Inconsolata&display=swap" | ||
| rel="stylesheet" | ||
| > | ||
| </head> | ||
| <body> | ||
| <h1 class="game_title">Memory Pairs Game</h1> | ||
| <div class="game_field"></div> | ||
| <script src="script.js"></script> | ||
| </body> | ||
| </html> |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,81 @@ | ||||||
| const cardsId = ["01", "02", "03", "04", "05", "06"]; | ||||||
| const cardsArr = [...cardsId, ...cardsId]; | ||||||
| const maxNumOfHiddenCards = 12; | ||||||
| const maxNumOfFlippedCards = 2; | ||||||
| const delayForHidden = 100; | ||||||
| const delayForClicked = 800; | ||||||
| const delayForAlert = 700; | ||||||
| let gameField = document.querySelector(".game_field"); | ||||||
| let numOfHiddenCards = 0; | ||||||
| let arrOfFlippedCardsId = []; | ||||||
| let firstFlippedContainer; | ||||||
| let secondFlippedContainer; | ||||||
|
|
||||||
| function createCard(id) { | ||||||
| let flipContainer = document.createElement("div"); | ||||||
| flipContainer.className = "flip-container"; | ||||||
|
||||||
| flipContainer.setAttribute("id", id); | ||||||
| gameField.append(flipContainer); | ||||||
|
||||||
| flipContainer.innerHTML = ` | ||||||
| <div class="flipper"> | ||||||
| <div class="front"> | ||||||
| <img src="img/paw.jpg"> | ||||||
| </div> | ||||||
| <div class="back"> | ||||||
| <img src="img/funny-cat_${id}.jpg"> | ||||||
| </div> | ||||||
| </div>`; | ||||||
| } | ||||||
| function createField() { | ||||||
| cardsArr.sort(function () { | ||||||
| return 0.5 - Math.random(); | ||||||
| }); | ||||||
| cardsArr.forEach((id) => createCard(id)); | ||||||
| } | ||||||
| function flipCard(event) { | ||||||
| if (arrOfFlippedCardsId.length == 0) { | ||||||
|
||||||
| if (arrOfFlippedCardsId.length == 0) { | |
| if (!arrOfFlippedCardsId.length) { |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use strict equality operator
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not using camelCase here ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probably it is a typo:)
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use destructuring
example
const [firstId, secondId] =arrOfFlippedCardsId
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| * { | ||
| padding: 0; | ||
| margin: 0; | ||
| box-sizing: border-box; | ||
| } | ||
| body { | ||
| background-color: rgb(223, 223, 223); | ||
| } | ||
| .game_title { | ||
| text-align: center; | ||
| margin-top: 5vh; | ||
| font-size: 32px; | ||
| font-family: "Inconsolata", monospace; | ||
| font-weight: 500; | ||
| } | ||
| .game_field { | ||
| display: grid; | ||
| grid-template-columns: repeat(4, 1fr); | ||
| gap: 10px 10px; | ||
| margin-left: auto; | ||
| margin-right: auto; | ||
| margin-top: 30px; | ||
| width: 630px; | ||
| } | ||
| .flip-container { | ||
| perspective: 1000px; | ||
| } | ||
|
|
||
| .flip-container.clicked .flipper { | ||
| transform: rotateY(180deg); | ||
| } | ||
| .flip-container.clicked.hidden { | ||
| visibility: hidden; | ||
| } | ||
| .front img, | ||
| .back img { | ||
| cursor: pointer; | ||
| width: 150px; | ||
| height: 150px; | ||
| border: 2px solid rgb(71, 68, 68); | ||
| border-radius:5px; | ||
| } | ||
| .flip-container { | ||
| width: 150px; | ||
| height: 150px; | ||
| } | ||
|
|
||
| .flipper { | ||
| transition: 0.6s; | ||
| transform-style: preserve-3d; | ||
| position: relative; | ||
| } | ||
|
|
||
| .front, | ||
| .back { | ||
| backface-visibility: hidden; | ||
| position: absolute; | ||
| top: 0; | ||
| left: 0; | ||
| } | ||
| .front { | ||
| z-index: 2; | ||
| transform: rotateY(0deg); | ||
| } | ||
| .back { | ||
| transform: rotateY(180deg); | ||
| } | ||
| @media (max-width: 660px) { | ||
| .game_field { | ||
| grid-template-columns: repeat(3, 1fr); | ||
| width: 320px; | ||
| gap: 5px 5px; | ||
| } | ||
| .front img, | ||
| .back img { | ||
| width: 103px; | ||
| height: 103px; | ||
| } | ||
| .flip-container { | ||
| width: 103px; | ||
| height: 103px; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ids