cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

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.

            
                  <body>
        <div class="boxesContainer">
            <div class="boxes zero" id="0"></div>
            <div class="boxes one" id="1"></div>
            <div class="boxes two" id="2"></div>
            <div class="boxes three" id="3"></div>
            <div class="settings">
                <h1>Simon</h1>
                <div id="counterDiv">
                    <div id="counter"><p id='count'>0</p></div>
                    <p id="counterLabel">COUNT</p>
                </div>
                <div class="buttonDiv">
                    <button class="butt" id="onOff"></button>
                    <p class="buttLabel" id="onOffLabel">ON/OFF</p>
                </div>
                <div class="buttonDiv">
                    <button class="butt" id="start"></button>
                    <p class="buttLabel" id="startLabel">START</p>
                </div>
                <div class="buttonDiv">
                    <button class="butt" id="strict"></button>
                    <p class="buttLabel" id="strictLabel">STRICT</p>
            </div>
        </div>
        </div>
        <div id='sound'></div>
        
    </body>
            
          
!
            
              @import url('https://fonts.googleapis.com/css?family=Alfa+Slab+One|VT323|Oswald');
*{
    margin: 0;
    padding: 0;
    font-family: 'Oswald';
}
.boxes {
    height: 250px;
    width: 250px;
    display: inline-block;
    margin:0;
    padding:0;
    border: 13px solid #333333;
    cursor: pointer;
}
.zero {
    background-color: #9F0F17;
    border-top-left-radius: 100%;
    margin: -8px;
}
.one {
    background-color: #094A8F;
    border-top-right-radius: 100%;
    margin: -8px;
}
.two {
    background-color: #00A74A;
    border-bottom-left-radius: 100%;
    margin: -8px;
}
.three {
    background-color: #CCA707;
    border-bottom-right-radius: 100%;
    margin: -8px;
}
.boxesContainer {
    height: 550px;
    width: 550px;
    margin: auto;
    margin-top: 50px;
}
.settings {
    height: 300px;
    width: 300px;
    border-radius: 100%;
    border: 13px solid #333333;
    position: relative;
    top: -390px;
    left: 90px;
    background-color: white;
}
h1 {
    font-size: 4em;
    margin-left: 70px;
}
#counterDiv {
    height: 70px;
    width: 70px;
    margin: auto;
}
#counter {
    min-height: 40px;
    max-height: 50px;
    width: 60px;
    margin: auto;

    background-color: #32050C;
    color: #511115;
    border-radius: 8px;
    border: 4px solid #333333;
}
#count{
    font-size: 2.2em;
    margin-left: 15px;
    font-family: 'VT323';

}
#counterLabel{
    margin-left: 15px;
}
.butt {
    height: 20px;
    width: 20px;
    border-radius: 100%;
    border: 1px solid #333333;
    background-color: #FC0102;
    box-shadow : 0px 2px 3px #222222;
    cursor: pointer;
}
.buttonDiv {
    display: inline-block;
    margin-top: 15px;
    margin-left: 47px;
}
.buttLabel{
    margin-left: -9px;
}

@media screen and (max-width: 500px){
  .boxesContainer {
      margin:0;
  }
}
            
          
!
            
              var onoff=0;
var strict=0;
var started=0;
var pattern=[];
var j=0;
var k=0;
var speed=2000;
var looped;
$(document).ready(function(){
    //buttons
    $('#onOff').click(function(){
        if (onoff===0){
            $(this).css('border', '4px solid #333333');
            $('#count').css('color', 'white');
            onoff=1;
        }
        else {
            $(this).css('border', '1px solid #333333');
            $('#count').css('color', '#511115');
            onoff=0;
            pattern=[];
            k=0;
            j=0;
            started=0;
            clearTimeout(looped);
            $('#count').html('0');
        }
    });
    $('#strict').click(function(){
        if (strict===0){
            $(this).css('border', '4px solid #333333');
            strict=1;
        }
        else {
            $(this).css('border', '1px solid #333333');
            strict=0;
        }
    });
    $('#start').click(function(){
        $(this).css('border', '4px solid #333333');
        setTimeout(function(){
            $('#start').css('border', '1px solid #333333');
        }, 500);
        if(onoff===1){
            clearTimeout(looped);
            $('#count').html('0');
            setTimeout(function(){
                pattern=[];
                k=0;
                j=0;
                started=1;
                start();
            }, 2500);
        }
    });
    
    
    $('.boxes').click(function(){
        if (started===1&&looped===0){
            console.log(pattern.length>0);
            if(pattern[k]+''===$(this).attr('id')){
                bright(pattern[k]);
                k++;
                if(k===pattern.length){
                    k=0;
                    $('#count').html(pattern.length);
                    if(pattern.length===20){
                        $('#count').html(':)');
                        clearTimeout(looped);
                        setTimeout(function(){
                            $('#count').html('0');
                            pattern=[];
                            k=0;
                            j=0;
                            started=1;
                            start();
                        }, 2500);
                    }
                    setTimeout(function(){
                        start();
                    }, 2000);
                }
            }
            else{
                if(strict===0){
                    console.log('else');
                    j=0;
                    k=0;
                    $('#count').html('!!!');
                    setTimeout(function(){loop(pattern);}, 2000);
                }
                else{
                    $('#count').html('!!!');
                    setTimeout(function(){
                        $('#count').html('0');
                        pattern=[];
                        k=0;
                        j=0;
                        start();
                    }, 2000);
                }
            }
        }
    });
    //end of buttons
});


function start(){
    var next=Math.floor(Math.random()*4);
    pattern.push(next);
    j=0;
    loop(pattern);
}

function loop(x){
    console.log('loop');
    bright(x[j]);
    j++;
    var pl=pattern.length;
    if (pl>5){
        speed=1600;
    }
    else {
        speed=2000;
    }
    if (pl>9){
        speed=1400;
    }
    if (pl>13){
        speed=1150;
    }
    console.log(speed);
    if(j<pl){
        looped=setTimeout(function(){loop(x);}, speed);
    }
    else {
        looped=0;
    }
}

function bright(x){
    console.log(pattern);
    switch (x){
        case 0:
            $("#sound").html('<audio autoplay="autoplay"><source src="https://s3.amazonaws.com/freecodecamp/simonSound1.mp3" type="audio/mpeg" />');
            $('.zero').css('background-color', '#cc4141');
            setTimeout(function(){
            $('.zero').css('background-color', '#9F0F17');
        }, 1000);
            break;
        case 1:
            $("#sound").html('<audio autoplay="autoplay"><source src="https://s3.amazonaws.com/freecodecamp/simonSound2.mp3" type="audio/mpeg" />');
            $('.one').css('background-color', '#42a0ff');
            setTimeout(function(){
            $('.one').css('background-color', '#094A8F');
        }, 1000);
            break;
        case 2:
            $("#sound").html('<audio autoplay="autoplay"><source src="https://s3.amazonaws.com/freecodecamp/simonSound3.mp3" type="audio/mpeg" />');
            $('.two').css('background-color', '#00ff6e');
            setTimeout(function(){
            $('.two').css('background-color', '#00A74A');
        }, 1000);
            break;
        case 3:
            $("#sound").html('<audio autoplay="autoplay"><source src="https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" type="audio/mpeg" />');
            $('.three').css('background-color', '#fff53d');
            setTimeout(function(){
            $('.three').css('background-color', '#CCA707');
        }, 1000);
            break;
    }
}
            
          
!
999px
Loading ..................

Console