Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <!DOCTYPE html>
<html lang="tr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Animals</title>
    <script src="javascript.js"></script>
    <link rel="stylesheet" href="style.css">
    <link href="https://fonts.googleapis.com/css?family=Roboto:400,700&amp;subset=latin-ext" rel="stylesheet">
</head>
<body>
    <div class="cards-container">
        <div class="left-side">
            <div class="box">
                <span class="text">Zaman</span>
                <div class="time">
                    &nbsp;
                </div>
            </div>
            <div class="box">
                <span class="text">Level</span>
                <div class="level">
                    1/4
                </div>
            </div>
            <div class="box">
                <span class="text">Puan</span>
                <div class="score">
                    0
                </div>
            </div>
        </div>
        <div class="right-side">
            <div class="flex-cards">

            </div>
        </div>
    </div>
</body>
</html>
            
          
!
            
              * {
    padding: 0;
    margin: 0;
    box-sizing: border-box;
}

body {
    font-family: Roboto;
}

img {
    max-width: 100%;
    max-height: 100%
}

.cards-container {
    padding: 0 15px;
    width: 1140px;
    margin: auto;
    max-width: 100%;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
}

.cards-container .flex-cards {
    margin: 0 -15px;
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    perspective: 1000px;
}

.cards-container .card {
    width: calc(25% - 30px);
    height: 200px;
    margin: 15px;
    position: relative;
    cursor: pointer;
    border-radius: 9px;
    overflow: hidden;
    box-shadow: 3px 3px 5px rgba(0,0,0,.1);
    transform-style: preserve-3d;
    transition: all .5s
}

.cards-container .card .front, .cards-container .card .back {
    background: #F44336;
    position: absolute;
    padding: 20px;
    width: 100%;
    height: 100%;
    backface-visibility: hidden;
}

.cards-container .card .back {
    transform: rotateY(180deg);
}

.cards-container .card .point {
    color: #FFF;
    position: absolute;
    left: 50%;
    top: 50%;
    backface-visibility: inherit;
    transform: rotateY(180deg) translate(-50%, -50%);
    font-size: 36px;
    transform-origin: left;
    opacity: 1;
    transition: all 300ms;
}

.cards-container .card.matched .point {
    opacity: 0;
    transition: all 300ms;
    transition-delay: 1500ms;
}

.cards-container .card.clicked, .cards-container .card.matched {
    pointer-events: none;
    transform: rotateY(180deg);
}

.cards-container .card.clicked .back {
    backface-visibility: inherit;
}

.left-side {
    width: 20%;
    padding: 0 15px
}

.left-side .box {
    box-shadow: 0 2px 8px 0px rgba(0,0,0,.2);
    padding: 15px;
    margin-bottom: 30px;
}

.left-side .box .text {
    font-weight: 700;
    text-transform: uppercase;
    display: block;
}

.left-side .box div {
    padding: 5px 10px;
    font-size: 23px
}

.left-side .box:first-child div {
    background: linear-gradient(#ffffff, #ffdf81)
}

.left-side .box:nth-child(2) div {
    background: linear-gradient(#ffffff, #9ef4ff)
}

.left-side .box:nth-child(3) div {
    background: linear-gradient(#ffffff, #f5ff91)
}

.left-side .box:last-child {
    margin-bottom: 0
}

.right-side {
    width: 80%;
    padding: 0 15px;
    position: relative;
}

.game-over, .game-win {
    position: absolute;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
}

.game-over .message, .game-win .message {
    font-size: 40px;
    color: #FFF;
    text-transform: uppercase;
    margin-bottom: 20px;
    text-align: center;
    text-shadow: 0 2px 3px rgba(0, 0, 0, 0.4);
}

.game-over button, .game-win button {
    padding: 15px 55px;
    text-transform: uppercase;
    background: linear-gradient(magenta, purple);
    border: 3px solid #FFF;
    box-shadow: 0px 2px 5px 2px rgba(0, 0, 0, 0.3);
    font-size: 22px;
    color: #FFF;
    cursor: pointer;
    outline: none;
    border-radius: 5px;
}

@keyframes fadeInUp{
    0% {
        opacity:0;
        transform:translate3d(0,100%,0)
    }
    to {
        opacity:1;
        transform:none
    }
}
            
          
!
            
              //timer
//level
//score
//sound click
var url = 'http://fkonyali.com/animals/',
    cardsC = document.getElementsByClassName('flex-cards'),
    card = document.getElementsByClassName('card'),
    cardClick = document.getElementsByClassName('clicked'),
    cardMatch = document.getElementsByClassName('matched'),
    score = document.getElementsByClassName('score'),
    level = document.getElementsByClassName('level'),
    wi_level = 1,
    right_side = document.getElementsByClassName('right-side'),
    level1cards = ['dog', 'cat', 'bear', 'elephant', 'dog', 'cat', 'bear', 'elephant'],
    level2cards = ['owl', 'lion', 'monkey', 'fish', 'chicken', 'rabbit', 'owl', 'lion', 'monkey', 'fish', 'chicken', 'rabbit'],
    level3cards = ['panda', 'tiger', 'unicorn', 'zebra', 'bat', 'giraffe', 'animal', 'chameleon','panda', 'tiger', 'unicorn', 'zebra', 'bat', 'giraffe', 'animal', 'chameleon'],
    level4cards = ['cheetah', 'crocodile', 'fox', 'goat', 'koala', 'narwhal', 'otter', 'sheep', 'dog', 'panda', 'cheetah', 'crocodile', 'fox', 'goat', 'koala', 'narwhal', 'otter', 'sheep', 'dog', 'panda'];

function shuffle(array) {
    var currentIndex = array.length,
        temporaryValue,
        randomIndex;

    while(0 != currentIndex) {
        randomIndex = Math.floor(Math.random() * currentIndex);
        currentIndex -= 1;

        temporaryValue = array[currentIndex];
        array[currentIndex] = array[randomIndex];
        array[randomIndex] = temporaryValue;
    }
    return array;
}

var level1cards_mix = shuffle(level1cards),
    level2cards_mix = shuffle(level2cards),
    level3cards_mix = shuffle(level3cards),
    level4cards_mix = shuffle(level4cards);

function innerItems(x,y,z) {
    for(i=0; i<y.length; i++) {
        x[0].innerHTML += 
            "<div class='card' data-img='"+btoa(z[i])+"'>"+
                "<div class='front'>"+
                    
                "</div>"+
                "<div class='back'>"+
                    
                "</div>"+
                "<div class='point'>"+

                "</div>"+
            "</div>";
    }
    innerItems_click(y);
}

function innerItems_click(y) {
    for(a=0; a<y.length; a++) {
        card[a].addEventListener("click", click_cards);
    }
}

var hasClickCard = false,
    clickable = false,
    firstCard, secondCard, point=0, totalPoint=0;

function click_cards(e) {
    var attr = atob(this.getAttribute("data-img"));
    if(clickable) return;
    this.classList.add('clicked');
    this.getElementsByClassName('back')[0].innerHTML = "<img src='"+url+attr+".svg' alt='"+attr+"' />";
    if(!hasClickCard) {
        //first click
        hasClickCard = true;
        firstCard = this;
        firstCardAttr = firstCard.getAttribute('data-img');
    }else {
        //second click
        hasClickCard = false;
        secondCard = this;
        secondCardAttr = secondCard.getAttribute('data-img');
        checkForMatch();
    }
}

var timer_circle;

function startTimer(duration, display) {
    var timer = duration, minutes, seconds;
    timer_circle = setInterval(function () {
        minutes = parseInt(timer / 60, 10)
        seconds = parseInt(timer % 60, 10);
        minutes = minutes < 10 ? "0" + minutes : minutes;
        seconds = seconds < 10 ? "0" + seconds : seconds;

        display.textContent = minutes + ":" + seconds;

        //if timer zero is game over
        if(timer == 0) {
            clearInterval(timer_circle);
            right_side[0].innerHTML += "<div class='game-over'>"+
                                            "<div class='message'>Kaybettin!</div>"+ 
                                            "<button id='play-again'>Tekrar Oyna</button>"+
                                        "</div>"
            var playAgain_btn = document.getElementById('play-again');
            playAgain_btn.addEventListener('click', play_again);
        }else {
            if (--timer < 0) {
                timer = duration;
            }
        }
    }, 1000);
}

function checkForMatch() {
    var lastMatch_Cards = cardMatch.length;
    console.log(lastMatch_Cards);
    //if match
    if(firstCardAttr === secondCardAttr) {
        disabledCards();
        firstCard.classList.add('matched');
        secondCard.classList.add('matched');
        //point
        point +=100;
        totalPoint +=point * 2;
        score[0].innerHTML = totalPoint;
        firstCard.getElementsByClassName('point')[0].innerHTML = "+"+point;
        secondCard.getElementsByClassName('point')[0].innerHTML = "+"+point;
        if(wi_level == 1 && lastMatch_Cards == 6) {
            //game-win
            clearInterval(timer_circle);
            right_side[0].innerHTML += "<div class='game-win'>"+
                                            "<div class='message'>Kazandın!</div>"+ 
                                            "<button id='second-level'>Sonraki Seviye</button>"+
                                        "</div>"
            var secondLevel_btn = document.getElementById('second-level');
                secondLevel_btn.addEventListener('click', secondLevel);
        }else if(wi_level == 2 && lastMatch_Cards == 10) {
            //game-win
            clearInterval(timer_circle);
            right_side[0].innerHTML += "<div class='game-win'>"+
                                            "<div class='message'>Kazandın!</div>"+ 
                                            "<button id='third-level'>Sonraki Seviye</button>"+
                                        "</div>"
            var thirdLevel_btn = document.getElementById('third-level');
                thirdLevel_btn.addEventListener('click', thirdLevel);
        }else if(wi_level == 3 && lastMatch_Cards == 14) {
            //game-win
            clearInterval(timer_circle);
            right_side[0].innerHTML += "<div class='game-win'>"+
                                            "<div class='message'>Kazandın!</div>"+ 
                                            "<button id='fourth-level'>Sonraki Seviye</button>"+
                                        "</div>"
            var fourthLevel_btn = document.getElementById('fourth-level');
                fourthLevel_btn.addEventListener('click', fourthLevel);
        }else if(wi_level == 4 && lastMatch_Cards == 18){
            //game-win
            clearInterval(timer_circle);
            right_side[0].innerHTML += "<div class='game-win'>"+
                                            "<div class='message'>Oyun bitti. Kazandın!</div>"+ 
                                            "<button id='play-again'>Tekrar Baştan Oyna</button>"+
                                        "</div>";
            wi_level = 1;
            var playAgain_btn = document.getElementById('play-again');
                playAgain_btn.addEventListener('click', play_again);
        }
    }else {
        unClickCards();
        //point
        point = 0;
    }
}

function secondLevel() {
    wi_level = 2;
    point = 0;
    right_side[0].innerHTML = "";
    level[0].innerHTML = "2/4";
    var level2cards_minutes = 85,
        display = document.querySelector('.time');
    startTimer(level2cards_minutes, display);
    right_side[0].innerHTML = "<div class='flex-cards'></div>";
    innerItems(cardsC,level2cards,level2cards_mix);
}

function thirdLevel() {
    wi_level = 3;
    point = 0;
    right_side[0].innerHTML = "";
    level[0].innerHTML = "3/4";
    var level3cards_minutes = 150,
        display = document.querySelector('.time');
    startTimer(level3cards_minutes, display);
    right_side[0].innerHTML = "<div class='flex-cards'></div>";
    innerItems(cardsC,level3cards,level3cards_mix);
}

function fourthLevel() {
    wi_level = 4;
    point = 0;
    right_side[0].innerHTML = "";
    level[0].innerHTML = "4/4";
    var level4cards_minutes = 210,
        display = document.querySelector('.time');
    startTimer(level4cards_minutes, display);
    right_side[0].innerHTML = "<div class='flex-cards'></div>";
    innerItems(cardsC,level4cards,level4cards_mix);
}

console.log(wi_level);

function disabledCards() {
    //is match
    firstCard.removeEventListener('click', click_cards);
    secondCard.removeEventListener('click', click_cards);
}

function unClickCards() {
    clickable = true;

    setTimeout(function(){
        firstCard.classList.remove('clicked');
        secondCard.classList.remove('clicked');
        clickable = false;
    },1500);
}

function play_again() {
    var display = document.querySelector('.time');
    point = 0;
    level[0].innerHTML = "1/4";
    score[0].innerHTML = "0";
    if(wi_level == 1) {
        var level1cards_minutes = 38;
        startTimer(level1cards_minutes, display);
        right_side[0].innerHTML = "<div class='flex-cards'></div>";
        innerItems(cardsC,level1cards,level1cards_mix);
    }else if(wi_level == 2) {
        var level2cards_minutes = 85;
        startTimer(level2cards_minutes, display);
        right_side[0].innerHTML = "<div class='flex-cards'></div>";
        innerItems(cardsC,level2cards,level2cards_mix);
    }else if(wi_level == 3) {
        var level3cards_minutes = 150;
        startTimer(level3cards_minutes, display);
        right_side[0].innerHTML = "<div class='flex-cards'></div>";
        innerItems(cardsC,level3cards,level3cards_mix);
    }else {
        var level4cards_minutes = 210;
        startTimer(level4cards_minutes, display);
        right_side[0].innerHTML = "<div class='flex-cards'></div>";
        innerItems(cardsC,level4cards,level4cards_mix);
    }
}

window.onload = function() {
    innerItems(cardsC,level1cards,level1cards_mix);
    var level1cards_minutes = 38,
        display = document.querySelector('.time');
    startTimer(level1cards_minutes, display);
}
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console