summaryrefslogtreecommitdiff
path: root/rannak/mangud/perenaine/memory/script.js
diff options
context:
space:
mode:
authorRasmus Luha <rasmus.luha@gmail.com>2022-09-17 01:02:22 +0300
committerRasmus Luha <rasmus.luha@gmail.com>2022-09-17 01:02:22 +0300
commit40d015a15bee7d0a51c28e20c29ff7045419b8f5 (patch)
tree2b37201e25502a71a13fb28f239d67f3c80573bc /rannak/mangud/perenaine/memory/script.js
parent20862b43316d6494bccfde391d0a426b9b015480 (diff)
mangud showcase
Diffstat (limited to 'rannak/mangud/perenaine/memory/script.js')
-rw-r--r--rannak/mangud/perenaine/memory/script.js76
1 files changed, 0 insertions, 76 deletions
diff --git a/rannak/mangud/perenaine/memory/script.js b/rannak/mangud/perenaine/memory/script.js
deleted file mode 100644
index 1a06fd9..0000000
--- a/rannak/mangud/perenaine/memory/script.js
+++ /dev/null
@@ -1,76 +0,0 @@
-const cards = document.querySelectorAll('.memory-card');
-
-let hasFlippedCard = false;
-let lockBoard = false;
-let firstCard, secondCard;
-let counter = 0;
-
-function flipCard() {
- if (lockBoard) return;
- if (this === firstCard) return;
-
- this.classList.add('flip');
-
- if (!hasFlippedCard) {
- hasFlippedCard = true;
- firstCard = this;
-
- return;
- }
-
- secondCard = this;
- checkForMatch();
-}
-
-function checkForMatch() {
- let isMatch = firstCard.dataset.framework === secondCard.dataset.framework;
-
- isMatch ? disableCards() : unflipCards();
-}
-
-function disableCards() {
- firstCard.removeEventListener('click', flipCard);
- secondCard.removeEventListener('click', flipCard);
- counter++;
-
- console.log(counter)
- if (counter >= 10) moveOnEnable();
- resetBoard();
-}
-
-function unflipCards() {
- lockBoard = true;
-
- setTimeout(() => {
- firstCard.classList.remove('flip');
- secondCard.classList.remove('flip');
-
- resetBoard();
- }, 1500);
-}
-
-function resetBoard() {
- [hasFlippedCard, lockBoard] = [false, false];
- [firstCard, secondCard] = [null, null];
-}
-
-(function shuffle() {
- cards.forEach(card => {
- let randomPos = Math.floor(Math.random() * 12);
- card.style.order = randomPos;
- });
-})();
-
-cards.forEach(card => card.addEventListener('click', flipCard));
-
-
-// Button func
-
-function moveOnEnable(){
- const button = document.querySelector(".btn");
- button.classList.remove('disabled');
- button.setAttribute('aria-disabled', false);
- console.log("done");
-
- counter = 0;
-}