-
Notifications
You must be signed in to change notification settings - Fork 23
Card feature #12
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?
Card feature #12
Changes from all commits
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 |
|---|---|---|
|
|
@@ -3,16 +3,44 @@ const cards = document.querySelectorAll('.memory-card') | |
| const restartBtn = document.querySelector('#restart-btn') | ||
| const timer = document.querySelector('#timer') | ||
| let counter = 0; | ||
| let memoryCounter = 5; | ||
|
|
||
| //increasing the counter | ||
| // For modifying cards | ||
| const makeCardsClickable = setTimeout(function(){ | ||
| cards.forEach(card=>{ | ||
| card.addEventListener('click',flipCard); // Makes cards clickable after the timer expires | ||
| card.children[1].style.display="block"; // Hides them after the timer expires | ||
| }) | ||
| },memoryCounter*1000); | ||
|
|
||
| // For timing the counters | ||
| const interval = setInterval(function(){ | ||
| counter++; | ||
| console.log() | ||
| timer.innerHTML = "<b>" + counter + "</b>"; | ||
| if(memoryCounter>0){ // Makes a check on memoryCounter and stops after 5 secs | ||
| memoryCounter--; | ||
| viewAllCards(); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this |
||
| timer.innerHTML = "<b>" + memoryCounter + "</b>"; // Changes inner HTML | ||
| } | ||
| else{ // Counter for timing the game | ||
| counter++; // This counter is set to motion only when the game starts i.e when memoryCounter expires | ||
| timer.innerHTML = "<b>" + counter + "</b>"; // Changes inner HTML | ||
| } | ||
| }, 1000); | ||
|
|
||
|
|
||
| // To view all cards | ||
| function viewAllCards(){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| // Cards are made viewable when memoryCounter is greater than 0 | ||
| if(memoryCounter>0){ | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this check should not be inside the function. To make a function reusable, it should do what its name suggests. Checks should be placed where the function is called. for ex: if we add a hint button which show the all cards , then we can reuse this function, but if this check is there we cannot reuse it |
||
| cards.forEach(card=>{ | ||
| card.children[1].style.display="none"; | ||
| }) | ||
| } | ||
| } | ||
|
|
||
|
|
||
| // When the game restarts all cards are made visible for 5secs | ||
| function restartGame(){ | ||
| window.location.reload() | ||
| window.location.reload(); | ||
| } | ||
|
|
||
| const flippedCards = [] | ||
|
|
@@ -59,9 +87,3 @@ function flipCard(e){ | |
| setTimeout(checkForMatch,0); | ||
| } | ||
| } | ||
|
|
||
| cards.forEach(card=>{ | ||
| card.addEventListener('click',flipCard); | ||
| }) | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.