Closed Tessabaxter12 closed 9 months ago
So your init()
function starts the timer. Outside of the init()
function you have made your cards clickable by adding an event listener to them:
gameBoard.forEach(function(card,i){
card.addEventListener("click",function(e){
handleMove(e,cardFronts[i])
})
})
What if you added the event listener at the same time that the timer starts within the init()
function?
I tried moving both the timer and the card flip handleMove function and it didn't change still can make the timer start in 2 spots? I'm not sure if I'm moving the write part or putting in the code incorrectly.
I got the timer to only work now in one spot. Thanks still working on the card matching
Could I get some help with matching the cards for pairs.
Hey Tessa, since we got the original issue fixed, let's open up a new one for getting the cards to match. Make sure to add the code where you're trying to make the match happen, along with any other relevant info to that issue.
What's the problem you're trying to solve?
The timer was only starting when you clicked the start game but you could start clicking the cards with out the time. I put the timer to function when you click the first card but now it can start in both places and sort of runs 2 timers at the same time.
Having trouble with only selecting two cards and determining if there is a match or no match. I'm doing an if or else statement with the image fronts of the array. Is that what you would do and can you please give me some advise.
Post any code you think might be relevant (one fenced block per file)
startButton.addEventListener("click",init) gameBoard.forEach(function(card,i){ card.addEventListener("click",function(e){ //Front of card flips over handleMove(e,cardFronts[i]) //Starts timer when first card flipped timer(); }) })
//Timer Function function timer(){ let sec = 60; let timer = setInterval(function(){ document.getElementById('time').innerHTML='00:'+sec; sec--; if (sec < 0) { clearInterval(timer); } }, 1000); }
//Tallys Wrong Moves
//handle move allows the back of cards to be clicked function handleMove(event,card){ console.log(event.target.style) event.target.style.backgroundImage =
url("../${card.image}")
}//should invoke an init function that also invoke the timer //Intializing the game function init() { timer() }
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
What is your best guess as to the source of the problem?
I have the time set to start in two spots. Which is wrong I think I need to make the cards not able to click until the start button is clicked.
What things have you already tried to solve the problem?
Switching the order
Paste a link to your repository here
https://github.com/Tessabaxter12/Memory_Game