| 377 | check(counter);}, 300); |
| 378 | }; |
| 379 | function check(counter){ |
| 380 | document.getElementById("mov").innerHTML = " "+(++moves); |
| 381 | |
| 382 | if(match==2 && counter[0].className!==counter[1].className){ |
| 383 | counter.forEach(box => { |
| 384 | box.childNodes[0].style.visibility="hidden"; |
| 385 | box.removeAttribute('a'); |
| 386 | |
| 387 | })} |
| 388 | if(match==4 && (counter[0].className!==counter[1].className || counter[1].className!==counter[2].className || counter[2].className!==counter[3].className)){ |
| 389 | counter.forEach(box => { |
| 390 | box.childNodes[0].style.visibility="hidden"; |
| 391 | box.removeAttribute('a'); |
| 392 | }); |
| 393 | } |
| 394 | cardDiv.forEach(card => { |
| 395 | if(card.hasAttribute('a')) |
| 396 | ++win; |
| 397 | }); |
| 398 | if(win==cardDiv.length){ |
| 399 | var d2=parseInt(Date.now()); |
| 400 | var time = getTime(d2-d1); |
| 401 | alert("Time Taken: "+time+"\nYou win : Press Play Again! ");} |
| 402 | win=0; |
| 403 | counter.length=0; |
| 404 | }; |
| 405 | function getTime(duration){ |
| 406 | seconds = Math.floor((duration / 1000) % 60), |
| 407 | minutes = Math.floor((duration / (1000 * 60)) % 60), |