Question: My JavaScript program needs to use SetTimout to make cards in a JS Memory game 'flip' back over, and needs to reveal numeric value for

My JavaScript program needs to use SetTimout to make cards in a JS Memory game 'flip' back over, and needs to reveal numeric value for each card when clicked. Currently, the program reveals the value of one card, but not the second and if there's a match, it removes both cards. However, I need to be able to reveal both cards, not just one and though the program doeds flip the one revealed card back over, it does not use setTimout.

My JS code is below:

var dvcard = document.querySelector(".card"); var body = document.body.innerHTML;

function replayGame() { document.body.innerHTML = body; }

//'flips' card when user clicks on div elements on page and invokes flipCard function function flipCard(cDiv, cardValue) { if(cardValue) { var dvcard = document.getElementsByClassName('cardValue');

//span is added when div element is clicked cDiv.innerHTML = ''+cardValue+'';

if(dvcard.length == 2) {

//Removes cards if first selected card matches the second if((dvcard[1].innerText) == (dvcard[0].innerText)) { while(dvcard.length > 0) { dvcard[0].parentNode.remove(); } } else {

while(dvcard.length > 0) { dvcard[0].parentNode.removeChild(dvcard[0]); } } } } }

My HTML Code is below:

Memory: A Game of Concentration

Flip a Card to Play

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!