memory game

by ian_smithz

HTML

<div class="container">
        <header>
            <h1>Memory Game</h1>	    
        </header>     

        <section class="score-panel">
        	<ul class="stars">
        		<li><span class="fa fa-star"></span></li>
        		<li><span class="fa fa-star"></span></li>
        		<li><span class="fa fa-star"></span></li>
        	</ul>

        	<span class="moves">0</span> Move(s)

            <div class="timer">
            </div>

            <div class="restart" onclick=startGame()>
        		<span class="fa fa-repeat"></span>
        	</div>
        </section>

        <ul class="deck" id="card-deck">

            <li class="card" type="1">
                <span class="fa fa-1"></span>
            </li>
            <li class="card" type="1">
                <span class="fa fa-1"></span>
            </li>

            <li class="card" type="2">
                <span class="fa fa-2"></span>
            </li>
            <li class="card" type="2">
                <span class="fa fa-2"></span>
            </li>

            <li class="card" type="3">
                <span class="fa fa-3"></span>
            </li>
            <li class="card" type="3">
                <span class="fa fa-3"></span>
            </li>

            <li class="card" type="4">
                <span class="fa fa-4"></span>
            </li>
            <li class="card" type="4">
                <span class="fa fa-4"></span>
            </li>

            <li class="card" type="5">
                <span class="fa fa-5"></span>
            </li>
            <li class="card" type="5">
                <span class="fa fa-5"></span>
            </li>

            <li class="card" type="6">
                <span class="fa fa-6"></span>
            </li>
            <li class="card" type="6">
                <span class="fa fa-6"></span>
            </li>

            <li class="card" type="7">
                <span class="fa fa-7"></span>
            </li>
            <li class="card"...

CSS

html {
	box-sizing: border-box;
}

*,
*::before,
*::after {
	box-sizing: inherit;
}

html,
body {
	width: 100%;
	height: 100%;
	margin: 0;
	padding: 0;
}

body {
	background: black;
	font-family: screwfix;
	color:white;
	font-size: 16px;
}

.container {
	display: flex;
	justify-content: center;
	align-items: center;
	flex-direction: column;
}

h1 {
	font-family: screwfix;
	color:white;
}


/*
 * Styles for the deck of cards
 */


.deck {
	width: 85%;
	background: black;
	padding: 1rem;
	border-radius: 4px;
	box-shadow: 8px 9px 26px 0 rgba(46, 61, 73, 0.5);
	display: flex;
	flex-wrap: wrap;
	justify-content: space-around;
	align-items: center;
	margin: 0 0 3em;
}

.deck .card {
	height: 200px;
	width: 200px;
	margin: 0.2rem 0.2rem;
/*	background: #ff0d00;*/
background-image: url(img/_logo.jpg);
	background-size: cover;
	font-size: 0;
	color: white;
	border-radius: 5px;
	cursor: pointer;
	display: flex;
	justify-content: center;
	align-items: center;
	box-shadow: 5px 2px 20px 0 rgba(46, 61, 73, 0.5);
}

.deck .card.open {
	transform: rotateY(0);
	background: #02b3e4;
	cursor: default;
	animation-name: flipInY;
	-webkit-backface-visibility: visible !important;
	backface-visibility: visible !important;
	animation-duration: .75s;
}

.deck .card.show {
	font-size: 33px;
}

.deck .card.match {
	cursor: default;
	background: #E5F720;
	font-size: 33px;
	animation-name: rubberBand;
	-webkit-backface-visibility: visible !important;
	backface-visibility: visible !important;
	animation-duration: .75s;
}

.deck .card.unmatched {
	animation-name: pulse;
	-webkit-backface-visibility: visible !important;
	backface-visibility: visible !important;
	animation-duration: .75s;
	background: #e2043b;
}

.deck .card.disabled {
	pointer-events: none;
	opacity: 0.9;
}

.card.open.show.disabled .fa, .match .fa{
	width: 100%;
	height: 100%;
}

/*.disabled .fa{
	width: 100%;
	height: 100%;
}*/

.fa-1 {
    background-image: url('https://via.placeholder.com/125x125');
    background-size:...

JavaScript

// cards array holds all cards
let card = document.getElementsByClassName("card");
let cards = [...card]
console.log(cards);

// deck of all cards in game
const deck = document.getElementById("card-deck");

// declaring move variable
let moves = 0;
let counter = document.querySelector(".moves");

// declare variables for star icons
const stars = document.querySelectorAll(".fa-star");

// declaring variable of matchedCards
let matchedCard = document.getElementsByClassName("match");

 // stars list
 let starsList = document.querySelectorAll(".stars li");

 // close icon in modal
 let closeicon = document.querySelector(".close");

 // declare modal
 let modal = document.getElementById("popup1")

 // array for opened cards
var openedCards = [];


// @description shuffles cards
// @param {array}
// @returns shuffledarray
function shuffle(array) {
    var currentIndex = array.length, temporaryValue, randomIndex;

    while (currentIndex !== 0) {
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex -= 1;
        temporaryValue = array[currentIndex];
        array[currentIndex] = array[randomIndex];
        array[randomIndex] = temporaryValue;
    }

    return array;
};


// @description shuffles cards when page is refreshed / loads
document.body.onload = startGame();


// @description function to start a new play 
function startGame(){
    // shuffle deck
    cards = shuffle(cards);
    // remove all exisiting classes from each card
    for (var i = 0; i < cards.length; i++){
        deck.innerHTML = "";
        [].forEach.call(cards, function(item) {
            deck.appendChild(item);
        });
        cards[i].classList.remove("show", "open", "match", "disabled");
    }
    // reset moves
    moves = 0;
    counter.innerHTML = moves;
    // reset rating
    for (var i= 0; i < stars.length; i++){
        stars[i].style.color = "#FFD700";
        stars[i].style.visibility = "visible";
    }
    //reset timer
    second = 0;
    minute...