Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <link href="https://fonts.googleapis.com/css?family=Alfa+Slab+One|VT323|Oswald" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Baloo+Bhaijaan|Righteous" rel="stylesheet">
    <link href='https://fonts.googleapis.com/css?family=Raleway' rel='stylesheet' type='text/css'>

<div id='heading'>
        <h2>Simon Game <br> FreeCodeCamp</h2>
    </div>
    <div class="container">
        <div class="header">
            <h1></h1>
        </div>
        <div class="simonBoard ">
            <div id="0" class="pad green"></div>
            <div id="1" class="pad red"></div>
            <div id="2" class="pad yellow"></div>
            <div id="3" class="pad blue"></div>
            <div class="board-controls">
                <div class="title">Simon</div>
                <div class="display inline">
                    <!-- <h5 class="label">COUNT</h5> -->
                </div>

                <div class="start inline">
                    <h5 class="label">START</h5>
                </div>

                <div class="strict inline">
                    <h5 class="label">STRICT</h5>
                </div>
                <div class="switch-container">
                    <p class="off inline">OFF</p>
                    <div class="switch outter-switch inline">
                        <div class="inner-switch"></div>
                    </div>
                    <p class="on inline">ON</p>
                </div>
            </div>
        </div>
    </div>
    <!-- end container -->

    <!--Footer-->
    <footer id="footer" class="footer text-center">
        <div class="contact">
            <div class="row">
                <a href="https://www.facebook.com/lindakovacsart" target="_blank"><span class="fa fa-facebook-f"></span>
                    Facebook | </a>
                <a href="https://twitter.com/lindakovacsart" target="_blank"><span class="fa fa-twitter"></span>
                    Twitter | </a>
                <a href="https://plus.google.com/u/1/112468176480762133222" target="_blank"><span class="fa fa-google-plus"></span>
                    Google+ | </a>
                <a href="https://www.linkedin.com/in/lindakovacsart" target="_blank"><span class="fa fa-linkedin"></span>
                    LinkedIn | </a>
                <a href="https://github.com/lindakovacs" target="_blank"><span class="fa fa-github"></span> GitHub |
                </a>
                <a href="https://www.freecodecamp.org/lindakovacs" target="_blank"><i class="fa fa-fire"></i>
                    FreeCodeCamp | </a> <!-- class="fa fa-free-code-camp" -->
                <a href="https://codepen.io/lindakovacs" target="_blank"><i class="fa fa-codepen"></i>Codepen</a>
            </div>
            <p>&copy 2018 Made with &#10084; by Linda Kovacs</a></p>
    </footer>
              
            
!

CSS

              
                body {
    background: url("https://i.pinimg.com/originals/be/50/39/be50393dc4e9a2da7471140d973f20c1.jpg");
    font-family: 'Righteous', cursive;
    color: black;
    width: 100%;
}

.container {
    margin: 0 auto;
    text-align: center;
    width: 100%;
}

h1 {
    font-size: 70px;
}

.simonBoard {
    margin: 0 auto;
    margin-top: 50px;
    border: solid 10px black;
    width: 600px;
    height: 600px;
    border-radius: 600px;
    box-shadow: -10px 10px 7px 0px rgba(50, 50, 50, 0.75);
}

.pad {
    margin: 0;
    float: left;
    position: relative;
    width: 290px;
    height: 290px;
    z-index: 8;
    border: 5px solid black;
}

.green {
    background-color:#0a0;
    -moz-border-radius: 300px 0 0 0;
    border-radius: 300px 0 0 0;
}

.green-active {
    background-color: darkgreen !important;
}

.red {
    background-color: red;
    -moz-border-radius: 0 300px 0 0;
    border-radius: 0 300px 0 0;
}

.red-active {
    background-color: darkred !important;
}

.yellow {
    background-color: yellow;
    -moz-border-radius: 0 0 0 300px;
    border-radius: 0 0 0 300px;
}

.yellow-active {
    background-color: #e6d47e !important;
}

.blue {
    background-color: blue;
    -moz-border-radius: 0 0 300px 0;
    border-radius: 0 0 300px 0;
}

.blue-active {
    background-color: darkblue !important;
}

.board-controls {
    border: 15px solid black;
    height: 245px;
    width: 245px;
    border-radius: 150px;
    background-color: white;
    clear: both;
    position: absolute;
    z-index: 10;
    margin-top: 160px;
    margin-left: 160px;
    box-shadow: -6px 8px 5px 0px rgba(50, 50, 50, 0.75);
}

.title {
    font-family: 'Alfa Slab One';
    font-size: 3.2em;
    margin-top: 30px;
    margin-bottom: 10px;
    /* font-weight: bold;
    font-size: 45px; */
}

.inline {
    display: inline-block;
    vertical-align: middle;
}

.display {
    border: solid 2px black;
    border-radius: 10px;
    color: white;
    width: 60px;
    height: 45px;
    font-size: 40px;
    background-color: black;
}

.label{
    color : #222;
    font-family : 'Oswald',Arial,sans;
    font-size:0.7em;
    margin-top:5px;
    text-align:center;
}

.start, .strict {
    text-align: center;
    margin: 0px;
    margin-left: 20px;
    border: solid 4px black;
    width: 20px;
    height: 20px;
    border-radius: 100%;
    color: black;
    line-height: 55px;
}

.start {
    background-color: #FC0102;
}

.strict {
    background-color: yellow;
}

.switch-container {
    margin-top: 10px;
}

.outter-switch {
    border: solid 2px black;
    width: 60px;
    height: 25px;
    background-color: black;
}

.outter-active {
    background-color: white !important;
}

.inner-switch {
    background-color: white;
    width: 30px;
    height: 25px;
    position: relative !important;
}

.inner-inactive {
    background-color: black !important;
}

#heading{
    font-family: 'Raleway', sans-serif;
    font-weight: bold;
    background-color: #0000FF;
    color: white;
    border-radius:15px;
    margin: auto;
    padding:10px;
    width: 50%;
    text-align: center;
}

#footer {
    background-color: #0000FF;
    color: #fff;
    /* border-radius: 20px;
    margin: 2em auto; */
    padding: 20px;
    width: 100%;
}

footer {
    text-align: center;
    font-size: 15px;
    margin: 20px;
}

footer a {
    color: #fff;
    position: relative;
    text-decoration: none;
    font-weight: bold;
}

footer a:hover {
    color: #000;
}
footer p {
    margin: 0;
    font-size: 17px;
}
              
            
!

JS

              
                //variables
payerTurn = [];
simonTurn = [];
const NUM_OF_LEVELS = 20;
var id, color, level = 0;
var strict = false;
var error = false;
var gameOn = false //switch to turn game on or off
var boardSound = [
    "https://s3.amazonaws.com/freecodecamp/simonSound1.mp3", //green
    "https://s3.amazonaws.com/freecodecamp/simonSound2.mp3", //red
    "https://s3.amazonaws.com/freecodecamp/simonSound3.mp3", //yellow
    "https://s3.amazonaws.com/freecodecamp/simonSound4.mp3" //blue
];

//start board sequence
$(document).ready(function () {
    $(".display").text("");
    //listener for switch button
    $(".switch").click(function () {
        gameOn = (gameOn === false) ? true : false;
    // console.log(gameOn);
        if (!gameOn) {
            $(".inner-switch").removeClass("inner-inactive");
            $(".switch").removeClass("outter-active");
            $(".display").text("");
            strict = false;
            error = false;
        }
        else {
            $(".inner-switch").addClass("inner-inactive");
            $(".switch").addClass("outter-active");
            $(".display").text("00");
            resetGame();
        }
    })

    //start game
    $(".start").click(function () {
        if (gameOn) {
            strict = false;
            error = false;
            level = 0;
            level++;
            simonTurn = []
            payerTurn = [];
            simonSequence();
        }
        else {
            $(".inner-switch").removeClass("inner-inactive");
            $(".switch").removeClass("outter-active");
            $(".display").text("");
        }
    })

    //user pad listener
    $(".pad").click(function () {
        id = $(this).attr("id");
        color = $(this).attr("class").split(" ")[1];
        playerSequence();
    });

    //strict mode listener
    $(".strict").click(function () {
        if (gameOn) {
            level = 0;
            level++;
            simonTurn = []
            payerTurn = [];
            strict = true;
            simonSequence();
        }
    })
})

//user sequence
function playerSequence() {
    payerTurn.push(id);
    console.log(id + " " + color);
    addClassSound(id, color);
    //check user sequence
    if (!checkPayerTurn()) {
        //if playing strict mode reset everything lol
        if (strict) {
            console.log("strict");
            simonTurn = [];
            level = 1;
        }
        error = true;
        displayError();
        payerTurn = [];
        simonSequence();
    }
    //checking end of sequence
    else if (payerTurn.length == simonTurn.length && payerTurn.length < NUM_OF_LEVELS) {
        level++;
        payerTurn = [];
        error = false;
        console.log("start simon")
        simonSequence();
    }
    //checking for winners
    if (payerTurn.length == NUM_OF_LEVELS) {
        displayWinner();
        resetGame();
    }

}

// simon sequence
function simonSequence() {
    console.log("level " + level);
    $(".display").text(level);
    if (!error) {
        getRandomNum();
    }
    if (error && strict) {
        getRandomNum();
    }
    var i = 0;
    var myInterval = setInterval(function () {
        id = simonTurn[i];
        color = $("#" + id).attr("class");
        color = color.split(" ")[1];
        console.log(id + " " + color);
        addClassSound(id, color);
        i++;
        if (i == simonTurn.length) {
            clearInterval(myInterval);
        }
    }, 1000);
}

//generate random number
function getRandomNum() {
    var random = Math.floor(Math.random() * 4);
    simonTurn.push(random);
}

// add temporary class and sound
function addClassSound(id, color) {
    $("#" + id).addClass(color + "-active");
    playSound(id)
    setTimeout(function () {
        $("#" + id).removeClass(color + "-active");
    }, 500);
}

// checking user seq against simon's
function checkPayerTurn() {
    for (var i = 0; i < payerTurn.length; i++) {
        if (payerTurn[i] != simonTurn[i]) {
            return false;
        }
    }
    return true;
}

// display error
function displayError() {
    console.log("error");
    var counter = 0;
    var myError = setInterval(function () {
        $(".display").text("Err");
        counter++;
        if (counter == 3) {
            $(".display").text(level);
            clearInterval(myError);
            payerTurn = [];
            counter = 0;
        }
    }, 500);
}

//display winner
function displayWinner() {
    var count = 0;
    var winInterval = setInterval(function () {
        count++;
        $(".display").text("Win");
        if (count == 5) {
            clearInterval(winInterval);
            $(".display").text("00");
            count = 0;
        }
    }, 500);
}

// play board sound
function playSound(id) {
    var sound = new Audio(boardSound[id]);
    sound.play();
}

// reset game
function resetGame() {
    payerTurn = [];
    simonTurn = [];
    level = 0;
    $(".display").text("00");
}
              
            
!
999px

Console