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

              
                <!DOCTYPE html>
<html>
    <head>
        <title>Simon game!</title>
        <meta name="description" content="A cool thing made with Gomix">
        <link id="favicon" rel="icon" href="https://gomix.com/favicon-app.ico" type="image/x-icon">
        <link href="https://fonts.googleapis.com/css?family=Cabin+Sketch|Julius+Sans+One|Permanent+Marker" rel="stylesheet">
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <link rel="stylesheet" href="public/style.css">
    </head>
    <body>
        <header>
            <h1>Simon game
      </h1>
        </header>
        <main>
            <div class="notice warning"></div>
            <div class="notice info"></div>
            <div class="board">
                <div class="slide1">
                    <div class="top">
                        <a href="#" id="pos1" data-pos="1">
                            <div class="dail left"></div>
                        </a>
                        <a href="#" id="pos2" data-pos="2">
                            <div class="dail right"></div>
                        </a>
                    </div>
                    <div class="bottom">
                        <a href="#" id="pos3" data-pos="3">
                            <div class="dail left"></div>
                        </a>
                        <a href="#" id="pos4" data-pos="4">
                            <div class="dail right"></div>
                        </a>
                    </div>
                </div>
                <div class="slide2">
                    <div class="center">
                        <div class="screen">
                            <label for="display"></label>
                            <div class="controls">
                                <div id="panel">
                                    <div id="em-display">
                                        count
                                        <input type="text" id="display" name="display">
                                    </div>
                                    <div id="em-start">
                                        <button type="button" id="start">start</button>
                                    </div>
                                    <div id="em-strict">
                                        <button type="button" id="strict" class="off" 1="">strict</button>
                                    </div>
                                </div>
                                <div style="height: 55px;position: relative;">
                                    <button type="button" class="off" id="state">on</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </main>
        <footer>
            <a href="https://github.com/tobi-et-al">Built with ❤️ &🍪 by toebee
        </a>
        </footer>
        <!-- Your web-app is https, so your scripts need to be too -->
        <script src="https://code.jquery.com/jquery-2.2.1.min.js" integrity="sha256-gvQgAFzTH6trSrAWoH1iPo9Xc96QxSZ3feW6kem+O00=" crossorigin="anonymous"></script>
        <script src="public/client.js"></script>
    </body>
</html>

              
            
!

CSS

              
                * {
    box-sizing: border-box;
}

body {
    font-family: 'Permanent Marker', cursive;
    margin: 0px auto;
    /* width: 500px; */
    text-align: center;
}

h1 {
    font-weight: bold;
    color: #f64f4f;
    text-shadow: rgb(0, 0, 0) 2px 2px;
    font-size: 3em;
    margin-bottom: 0px;
}

.bold {
    font-weight: bold;
}

p {
    max-width: 600px;
}

.screen {
    width: 100%;
    margin: 0 auto;
}

.controls {
    margin-top: 45px;
    height: 100px;
    padding-left: 5px;
}

.panel {
    clear: both;
}

.top .left {
    border: 15px solid rgb(74, 74, 74);
    width: 50%;
    float: left;
    height: 100%;
    border-radius: 50% 0% 0% 0%;
    background-color: rgb(0, 123, 82);
}

.top .right {
    border: 15px solid rgb(74, 74, 74);
    width: 50%;
    float: left;
    height: 100%;
    border-radius: 0% 50% 0% 0%;
    background-color: #00007b;
}

.bottom .left {
    border: 15px solid rgb(74, 74, 74);
    width: 50%;
    float: left;
    height: 100%;
    border-radius: 0% 0% 0% 50%;
    background: #636300;
}

.bottom .right {
    border: 15px solid rgb(74, 74, 74);
    width: 50%;
    float: left;
    height: 100%;
    border-radius: 0% 0% 50% 0%;
    background-color: rgb(138, 0, 0);
}

.center {
    clear: both;
    border: 15px solid rgb(74, 74, 74);
    border-radius: 50% 50% 50% 50%;
    margin: 75px auto auto 75px;
    position: absolute;
    background: lightgray;
    width: 250px;
    height: 250px;
}

.top .dail.left.active {
    transition: 1s all;
    background-color: rgb(0, 255, 171) !important;
}

.top .dail.right.active {
    transition: 1s all;
    background-color: rgb(0, 147, 255) !important;
}

.bottom .dail.left.active {
    transition: 1s all;
    background-color: #ffe200 !important;
}

.bottom .dail.right.active {
    transition: 1s linear;
    background-color: red !important;
}

main {
    margin: auto;
    width: 402px;
    padding-top: 30px;
}

.board {
    max-height: 402px;
    /* overflow: hidden; */
    max-width: 402px;
    /* height: 402px; */
    /* width: 402px; */
}

form {
    margin-bottom: 25px;
    padding: 15px;
    background-color: cyan;
    display: inline-block;
    width: 100%;
    max-width: 340px;
    border-radius: 3px;
}

input {
    display: block;
    margin-bottom: 10px;
    padding: 5px 5px 5px 17px;
    width: 100%;
    border: 1px solid lightgrey;
    border-radius: 3px;
    background: rgb(66, 52, 52);
    font-size: 1.2em;
    color: crimson;
    letter-spacing: 5px;
    font-family: monospace;
    text-align: center;
    font-weight: bold;
    max-width: 58px;
    height: 105%;
    /* margin-left: 25px; */
}

button {
    font-size: 14px;
    border-radius: 3px;
    background-color: lightgrey;
    border: 1px solid grey;
    box-shadow: 2px 2px teal;
    cursor: pointer;
    height: 30px;
    margin-left: 5px;
}

button:active {
    box-shadow: none;
}

li {
    margin-bottom: 5px;
}

footer {
    margin-top: 40px;
}

a {
    color: #BBBBBB;
}

.nicejob {
    text-decoration: line-through;
}

button.on, #state.on {
    background-color: yellow;
    color: #f64f4f;
    text-shadow: #ffffff 0px 1px 3px;
    /* font-weight: bold; */
    transition: all 0.0s;
    width: 75%;
    margin-left: 0%;
}

#state {
    color: grey;
}

label {
    /* font-size: 2em; */
    /* line-height: 3em; */
}

.notice {
    font-family: monospace;
    color: crimson;
    font-size: 1.2em;
    height: 1em;
    /* padding-top: 40px; */
}

.notice.info {
    color: blue;
    font-size: 1.2em;
}

button#state {
    width: 75%;
    margin-left: 0%;
}

button#strict.on {
    font-size: 14px;
    border-radius: 3px;
    background-color: lightgrey;
    border: 1px solid grey;
    box-shadow: 2px 2px teal;
    cursor: pointer;
    /* height: 40px; */
    background-color: yellow;
    width: auto;
    margin-left: 6px;
}

.slide1 {
    height: 402px;
    width: 402px;
    position: absolute;
}
.slide2 {
    height: 402px;
    width: 402px;
}
.top,.bottom {
    height: 50%;
}

div#em-start {
    float: left;
    height: 30px;
    margin-top: 25px;
}

div#em-display {
    float: left;
    height: 30px;
    font-size: 18px;
    margin-left: 25px;
}

div#em-strict {
    float: left;
    height: 30px;
    margin-top: 25px;
}

div#panel {
    height: 64px;
    position: relative;
}

@media (max-width: 402px) {
    .slide1 {
        height: 320px;
        width: 320px;
        position: absolute;
    }.slide2 {
        height: 320px;
        width: 320px;
    }

    div#panel {
        height: 59px;
        position: relative;
    }

    main {
        width: 320px;
        margin: auto;
        height: 320px;
        position: relative;
    }

    .controls {
        margin-top: 25px;
        padding-left: 2px;
    }

    button {
        font-size: 12px;
        border-radius: 3px;
        background-color: lightgrey;
        border: 1px solid grey;
        box-shadow: 2px 2px teal;
        cursor: pointer;
        height: 30px;
        margin-left: 0px;
        width: 99%;
        padding: 0px;
        margin-right: 2px;
    }

    input {
        display: block;
        margin-bottom: 10px;
        padding: 5px 5px 5px 17px;
        width: 100%;
        border: 1px solid lightgrey;
        border-radius: 3px;
        background: rgb(66, 52, 52);
        font-size: 1em;
        color: crimson;
        letter-spacing: 3px;
        font-family: monospace;
        text-align: center;
        /* font-weight: bold; */
        max-width: 44px;
        height: 105%;
    }

    div#em-start {
        float: left;
        height: 30px;
        margin-top: 16px;
        margin-left: 0px;
        padding-left: 0px;
    }

    div#em-display {
        float: left;
        height: 30px;
        font-size: 11px;
        margin-left: 10px;
    }

    div#em-strict {
        float: left;
        height: 30px;
        margin-top: 16px;
    }

    div#panel {
        height: 60px;
        position: relative;
        margin-left: 10px;
    }

    #em-start button#start {
        width: 44px;
    }

    button#state {
        width: 75%;
        margin-left: 0%;
    }

    .center {
        clear: both;
        border: 15px solid rgb(74, 74, 74);
        border-radius: 50% 50% 50% 50%;
        margin: 20% 0% 0% 20%;
        position: absolute;
        background: lightgray;
        width: 60%;
        height: 60%;
    }

    .screen {
        width: 103%;
        margin: 0 auto;
    }
}

              
            
!

JS

              
                $(function() {
    var data = {};
    var controller = {
        init: function() {
            this.actions = "button";
            this.state = false;
            this.count = 1;
            this.StrictMode = false;
            this.moves = {
                user: [],
                pc: []
            };
            //set interval to check value
            this.playInterval = 6000;
            view.init();

        },
        power: function(v) {
            this.state = v;
            this.position = -1;

            if (this.state) {
                this.screenOn();
                this.turn = 0
                view.enableDail();
            }
        },
        sound: function(key) {
            switch (key) {
            case 1:
                var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound1.mp3');
                audio.play();
                break;
            case 2:
                var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound2.mp3');
                audio.play();
                break;
            case 3:
                var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound3.mp3');
                audio.play();
                break;
            case 4:
                var audio = new Audio('https://s3.amazonaws.com/freecodecamp/simonSound4.mp3');
                audio.play();
                break;
            default:
                var audio = new Audio('https://cdn.gomix.com/d7877e8a-d25e-4f15-971f-e734fd29458d%2FWrong-answer-soundx.mp3');
                audio.play();
            }
        },
        initGame: function(randomPlay) {
            setTimeout(function() {
                if (controller.state) {
                    //generate play
                    var randomPlay = controller.generatePlay();
                    //save play
                    controller.moves.pc.push(randomPlay);
                    //updated display
                    view.setScreen(controller.count);
                    //make play
                    controller.makeMove();
                }
            }, 2000);

        },
        makeMove: function() {
            this.turn = 0
            var moves = this.moves.pc;

            if (moves.length > 0) {

                var sequence = Promise.resolve()

                for (var i = 0; i < moves.length; i++) {
                    (function() {
                        // define closure to capture i at each step of loop
                        var capturedindex = i
                        sequence = sequence.then(function() {
                            return controller.displayPlay(moves[capturedindex])
                        }).then(function() {// ready for user to play

                        }).catch(function(err) {//console.log('Error ' + err)
                        })
                    }())
                    // invoke closure function immediately
                }
                ;sequence = sequence.then(function() {
                    return new Promise(function(resolve, reject) {
                        controller.turn = 1;
                        view.setWarningNotice("")
                        view.setInfoNotice(" Your Turn!")
                        resolve();
                    }
                    );
                });
            }

            this.countdown = setTimeout(function() {
                if (controller.moves.user.length < 1) {
                    controller.checkPlay(true);
                }
            }, (1000 * controller.moves.pc.length) + controller.playInterval);
        },
        clearCountdown: function() {
            clearTimeout(this.countdown);
        },
        checkPlay: function(nodata) {
            //console.log('...checking')
            //clear timer
            this.clearCountdown();
            //console.log(this.moves.pc);
            var userMoves = this.moves.user;
            var pcMoves = this.moves.pc.slice(0, userMoves.length);
            var position = this.position;

            if (this.moves.pc[position] !== this.moves.user[position] || nodata == true) {

                //console.log('moves dont match', this.moves.pc[position], this.moves.user[position]);

                // play annoying buzz sound
                this.sound(null);
                //alert on screen
                view.setScreen("!!");
                //replay move
                if (nodata) {
                    view.setWarningNotice("Times up, Try again")
                    view.setInfoNotice("")
                } else {
                    view.setWarningNotice("Wrong button, try again!")
                    view.setInfoNotice("")

                }
                setTimeout(function() {
                    if (controller.StrictMode == true) {
                        //console.log("strict mode")
                        controller.moves.user = [];
                        controller.moves.pc = [];
                        controller.count = 1;
                        controller.position = -1;
                        controller.initGame();

                    } else {

                        view.setScreen(controller.count);
                        controller.position = -1;
                        controller.moves.user = [];
                        controller.makeMove();
                    }
                }, 500)

            } else {
                //check if next entry is available
                controller.sound(this.moves.user[position])
                if (this.moves.pc[position + 1] == undefined) {
                    view.setInfoNotice("");
                    view.setWarningNotice("");

                    if ((controller.count) < 20) {

                        view.setWarningNotice("")
                        view.setInfoNotice("Good job!")
                        setTimeout(function() {
                            controller.moves.user = [];
                            controller.position = -1;
                            controller.count += 1;
                            controller.initGame();
                        });
                    } else {
                        view.setWarningNotice("");
                        view.setInfoNotice("Congrats! You WON!");
                        setTimeout(function() {
                            //console.log("strict mode")
                            controller.moves.user = [];
                            controller.moves.pc = [];
                            controller.count = 1;
                            controller.position = -1;
                            controller.initGame();
                        }, 500);

                    }
                }
            }
        },
        displayPlay: function(v) {
            return new Promise(function(resolve, reject) {
                view.updateDail('#pos' + v)
                controller.sound(v)
                setTimeout(function() {
                    $('.dail').removeClass('active');
                }, 500);
                setTimeout(function() {
                    resolve();
                }, 1000);
            }
            )
        },
        userEntry: function(v) {

            this.moves.user.push(v);
            this.position = this.position + 1;
            setTimeout(function() {
                $('.dail').removeClass('active');
                controller.checkPlay(false)
            }, 500);
        },
        generatePlay: function() {
            return Math.ceil(Math.random() * 4);
        },
        screenOn: function() {
            view.setScreen('__');
        },
        getActionButtons: function() {
            return this.actions;
        },
        setStrictMode: function(state) {
            this.StrictMode = state;
        }

    };
    var view = {
        init: function() {
            this.actions()
            this.screenId = "#display";
            this.noticewarning = ".notice.warning";
            this.noticeinfo = ".notice.info";
            view.setScreen();
        },
        actions: function() {
            $(view.getActionButtons()).on('click', function(e) {

                switch (e.target.id) {
                case "state":
                    var elem = $('#' + e.target.id);
                    if (elem.hasClass('off')) {
                        controller.power(true);
                        $('#' + e.target.id).removeClass('off').addClass('on')
                    } else {
                        controller.power(false)
                        $('#' + e.target.id).removeClass('on').addClass('off');
                        view.setScreen("");

                    }
                    break;
                case "start":
                    if (controller.state) {
                        var elem = $('#' + e.target.id);
                        if ($('button#start').text() === "restart") {
                            //console.log("yes")
                            view.setInfoNotice("restarting game...")
                            view.setWarningNotice("")
                        } else {
                            view.setInfoNotice("starting game...")
                            view.setWarningNotice("")
                        }
                        $('button#start').text("restart");
                        controller.count = 1;
                        controller.moves = {
                            user: [],
                            pc: []
                        };
                        controller.clearCountdown();
                        controller.initGame();
                    }
                    break;
                case "strict":
                    if (controller.state) {
                        var elem = $('#' + e.target.id);
                        controller.moves = {
                            user: [],
                            pc: []
                        };
                        if (elem.hasClass('off')) {
                            $('#' + e.target.id).removeClass('off').addClass('on')
                            controller.setStrictMode(true);
                        } else {
                            $('#' + e.target.id).removeClass('on').addClass('off');
                            controller.setStrictMode(false);
                        }
                    }
                    break;
                }
            })
        },
        enableDail: function() {
            $('.board a').on('click', function() {
                if (controller.turn == 1) {
                    $(this).find('.dail').addClass('active');
                    controller.userEntry($(this).data('pos'));
                }
            });
        },
        disableDail: function() {
            $('.board a').attr('disabled', 'disabled');
        },
        updateDail: function(id) {
            $(id).find('.dail').addClass('active');
        },
        setScreen: function(v) {
            $(this.screenId).val(v);
        },
        setWarningNotice: function(v) {
            $(this.noticewarning).text(v);
        },
        setInfoNotice: function(v) {
            $(this.noticeinfo).text(v);
        },
        getActionButtons: function() {
            return controller.getActionButtons();
        }

    };
    controller.init();
});

              
            
!
999px

Console