JSFiddle - React, Tailwind, and code Playground

by Anchit Gupta

HTML

<table align="center" border="0">
  <tr>
    <td width="430" rowspan="3">    
        <div class="container">
            <div id="a1" class="card"></div>
            <div id="a2" class="card"></div>
            <div id="a3" class="card"></div>
            <div id="a4" class="card"></div>
            <div id="b1" class="card"></div>
            <div id="b2" class="card"></div>
            <div id="b3" class="card"></div>
            <div id="b4" class="card"></div>
            <div id="c1" class="card"></div>
            <div id="c2" class="card"></div>
            <div id="c3" class="card"></div>
            <div id="c4" class="card"></div>
            <div id="d1" class="card"></div>
            <div id="d2" class="card"></div>
            <div id="d3" class="card"></div>
            <div id="d4" class="card"></div>
        </div>   
    </td>
    <td width="161" height="95" align="center" valign="middle"></td>
  </tr>
  <tr>
    <td height="148" valign="top">
    	<div class=scoreboard></div>
    </td>
  </tr>
  <tr>
    <td height="148" valign="bottom"><input id="clicky" type="button" value="Restart"/></td>
  </tr>
  <tr>
    <td height="59" align="center"><div id="msg"></div></td>
    <td>
    </td>
  </tr>
</table>

CSS

body{
    margin:0;
    padding:0;
	font-family: Arial;
	font-weight: bold;
}

#clicky {
	width: 100px;
	height: 40px;
    background-color: #F4F4F4;
    color: #666;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
	font-weight: bold;
	margin-bottom: 20px;
}

.clicky {
	width: 100px;
	height: 40px;
    background-color: #F4F4F4;
    color: #666;
    border-radius: 5px;
    -moz-border-radius: 5px;
    -webkit-border-radius: 5px;
	font-weight: bold;
	margin-bottom: 20px;
}

.container{
    width:412px;
	height:412px;
}

.scoreboard{
	background-color: grey;
	border-radius: 10px;
	-moz-border-radius: 10px;
	-webkit-border-radius: 10px;
	color: #FFF;
    height:80px;
    width:160px;
	padding-left: 12px;
	padding-top: 17px;
}

.card{
    width:100px;
    height:100px;
    float:left;
    background-color:#ccc;
    margin-bottom:3px;
	margin-right:3px;
	position: relative;
}

.card:after {
    content:"";
    display:block;
    position:absolute;
    left:0;
    right:0;
    top:0;
    bottom:0;
    background: lightgrey;
}

.card:hover:after {
	width:94px;
    height:94px;
	border:3px solid black;
	
}

.show.card:after{
	display:none;
	border: 0;	
}

.show:hover{
	width:94px;
    height:94px;
	border:3px solid black;
}

.lock{
	pointer-events:none;
}
.lock:hover{
	pointer-events:none;
}

JavaScript

var highscore = 0;
var rounds = 0;

var score = 0;
var pairs = 0;

function divs(){
    var colors = [
        "orange","orange","pink","pink","red","red","purple","purple",
        "blue","blue","green","green","brown","brown","yellow","yellow"];
    
    var divs = document.getElementsByClassName("card");
    
    while (divs.length > 0) {
        var i = Math.floor(Math.random() * colors.length);
        divs[0].style.backgroundColor = colors[i];
        colors.splice(i, 1);
        divs = [].slice.call(divs, 1);
    }
}

function restart(){
    if(score>highscore){
        highscore=score;		
    }
    pairs = 0;
    score = 0;
    rounds++
        $("div").removeClass("show lock");
    
    $('.scoreboard').html("Top score: " + highscore
                          + "<br>Current score: " + score
                          + "<br>Games played: " + rounds);
    divs();
}

divs();

$('.scoreboard').html("Top score: " + highscore
                      + "<br>Current score: " + score
                      + "<br>Games played: " + rounds);

var pick1 = false;
var pick2 = false;
var id1;
var id2;

$('.card').click(function(){
    
    if(pick1) {
        pick2 = $(this).css("background-color");
        id2 = this.id;
        $(this).addClass("show")
        
        if(pick1 == pick2 && id1!=id2){
            $('#msg').html("Match found! :-)");
            $('#' + id1 + ', #' + id2).addClass("lock");
            score += 100;
            pairs++
                $(this).addClass("show")
                if (pairs == 8){
                    $('#msg').html("Game completed! =D");
                    setTimeout(function (){
                        restart()},1500);
                }
        }
        else {
            $('#msg').html("Sorry, no match :-(");
            setTimeout(function (){
                $('#' + id1 + ', #' + id2).removeClass("show")
            },300);
            score -= 10;
        }
        $('.scoreboard').html("Top score: " + highscore
          ...