css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

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.

            
              
    <body class="withMouse_ON start_ON">
    
    <div class="option" id="option">
        <span class="withButton" id="withButton">Play with Mouse</span>
        <span class="withMouse" id="withMouse">Play with Button</span>
    </div>

    <div id="time"></div>
    
    <div class="field start">
        <div class="inner">
            <div class="header">
                <h1>Mathness</h1>
                <p>quick thinking and responsing</p>
            </div>
            <div class="button start" id="start">Start</div>
        </div>
    </div>
    
    <div class="field main">
        <div class="inner">
            <div class="notification">
                <span class="level">Level <span id="level">1</span></span>●<span class="counter" id="counter">0</span>
            </div>
            <div class="screen">
                <span class="first" id="first"></span>+<span class="second" id="second"></span>
                <div class="result" id="result"></div>
            </div>
            <div class="buttons withButton">
                <div class="button true" id="true">True</div>
                <div class="button false" id="false">False</div>
            </div>
            <div class="buttons withMouse">
                <p>Left click : <span>True</span></p>
                <p>Right click : <span>False</span></p>
            </div>
        </div>
    </div>
    
    <div class="field end level1">
        <div class="inner">
            <div class="scoreboard">
                <div class="header">Your Score</div>
                <div class="level">Level <span id="level">1</span></div>
                <div class="counter" id="counter">0</div>
                <div class="text level1">Bad, keep trying!</div>
                <div class="text level2">Good, try more for best.</div>
                <div class="text level3">Genius, don't play more!</div>
                <div class="text level4">Heey, I said you "Don't play more!" dude.</div>
            </div>
            <div class="button replay" id="replay">Replay</div>
        </div>
    </div>








</body>

            
          
!
            
              /*
*
* Css reset
*
*/

html,
body,
div,
span,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
code,
del,
dfn,
em,
img,
q,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
dialog,
figure,
footer,
header,
hgroup,
nav,
section {
    margin: 0;
    padding: 0;
    border: 0;
    font-weight: inherit;
    font-style: inherit;
    font-size: 100%;
    font-family: inherit;
    vertical-align: baseline;
    text-decoration: none;
    list-style: none;
}
img {
    width: 100%
}
a:focus {
    outline: thin dotted;
}
a:hover,
a:active {
    outline: 0;
}
a img {
    border: 0;
}
*,
*::before,
*::after {
    -webkit-text-rendering: optimizeLegibility;
    -moz-text-rendering: optimizeLegibility;
    -ms-text-rendering: optimizeLegibility;
    -o-text-rendering: optimizeLegibility;
    text-rendering: optimizeLegibility;
    -webkit-font-smoothing: antialiased;
    -moz-font-smoothing: antialiased;
    -ms-font-smoothing: antialiased;
    -o-font-smoothing: antialiased;
    font-smoothing: antialiased;
}
-webkit-::selection,
-moz-::selection,
-ms-::selection,
::selection{
    display: none;
}
.anim03_1 {
    -webkit-transition: all .3s 0;
    -moz-transition: all .3s 0;
    -ms-transition: all .3s 0;
    -o-transition: all .3s 0;
    transition: all .3s 0;
}
.anim03_2 {
    -webkit-transition: all .3s .15s;
    -moz-transition: all .3s .15s;
    -ms-transition: all .3s .15s;
    -o-transition: all .3s .15s;
    transition: all .3s .15s;
}
.anim03_3 {
    -webkit-transition: all .3s .3s;
    -moz-transition: all .3s .3s;
    -ms-transition: all .3s .3s;
    -o-transition: all .3s .3s;
    transition: all .3s .3s;
}
.anim04c {
    -webkit-transition: all .4s cubic-bezier(.5, .35, .15, 1.4) !important;
    -moz-transition: all .4s cubic-bezier(.5, .35, .15, 1.4) !important;
    -ms-transition: all .4s cubic-bezier(.5, .35, .15, 1.4) !important;
    -o-transition: all .4s cubic-bezier(.5, .35, .15, 1.4) !important;
    transition: all .4s cubic-bezier(.5, .35, .15, 1.4) !important;
}
/*
*
* Css reset end.
* Reedited for the theme specifics -bg image, body box-sizing etc.
*
*/

html,
body {
    height: 100%!important;
    top: 0!important;
    font-family: "Open Sans", sans-serif;
}
html {
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}
body {
    overflow-x: hidden;
    overflow-y: auto;
    color: #eee;
}
/*---------*/

.field{
    width: 100%;
    height: 100%;
    position: absolute;
    top: 0;left: 0;
    background: #fff;
    color: #888;
}
.field > .inner{
    width: 95%;
    min-width: 240px;
    max-width: 540px;
    height: 100%;
    min-height: 560px;
    margin: 0 auto;
    position: relative;
    top: 50%;
    -webkit-transform:translateY(-50%);
    -moz-transform:translateY(-50%);
    -ms-transform:translateY(-50%);
    -o-transform:translateY(-50%);
    transform:translateY(-50%);
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
}
.button{
    display: inline-block;
    padding: 15px 20px;
    font-weight: 900;
    text-align: center;
    text-transform: uppercase;
    letter-spacing: 2px;
    border: 4px solid transparent;
    cursor: pointer;
}
.button:hover{
    border-color: #888;
    background: transparent !important;
    color: #888;
}





.start_ON .field.start,
.main_ON .field.main,
.end_ON .field.end{
    visibility: visible;
    opacity: 1;
    z-index: 1;
    
    display: block;
}
.start_ON .field.main,
.start_ON .field.end,
.main_ON .field.start,
.main_ON .field.end,
.end_ON .field.start,
.end_ON .field.main{
    visibility: hidden;
    opacity: 0;
    z-index: 0;
    
    display: none;
}





.main_ON #option{
    display: none;
}
.option{
    width: 100%;
    font-size: 14px;
    font-weight: 600;
    position: absolute;
    top: 40px;z-index: 2;
    text-align: center;
    color: #888;
}
.option> *{
    cursor: pointer;
}
.withButton_ON .withMouse,
.withMouse_ON .withButton{
    display: none;
}
.withButton_ON .withButton,
.withMouse_ON .withMouse{
    display: block;
}
.withMouse p{
    text-transform: none;
}
.withMouse p span{
    font-weight: 900;
    text-transform: uppercase
}
.withMouse p:first-child span{
    color: #2ecc71;
}
.withMouse p:last-child span{
    color: #ec6d67;
}






#time{
    width: 0;
    height: 20px;
    position: absolute;
    top: 0;left: 0;z-index: 3;
    background: #2ecc71;
}
#time.medium{
    background: #f1c40f;
}
#time.high{
    background: #ec6d67;
}






.start .header{
    padding: 175px 0 125px 0;
}
.start .header h1{
    font-size: 40px;
    font-weight: 900;
}
.start .header p{
    padding: 30px;
    font-size: 20px;
}
.start .button.start{
    border-color: #2cbeff;
    background: #2cbeff;
    color: #fff;
}
.start .button.start:hover{
    border-color: #2cbeff;
    color: #2cbeff;
}






.main .notification{
    width: 100%;
    height: 30px;
    padding-top: 100px;
    line-height: 30px;
    text-align: center;
}
.main .level{
    margin-right: 10px;
}
.main .counter{
    margin-left: 10px;
}
.main .screen{
    padding: 80px 0;
    font-size: 50px;
    font-weight: 900;
}
.main .first,
.main .second{
    margin: 0 10px;
}
.main .result{
    font-size: 70px;
    padding-top: 40px;
}

.main .button{
    width: 100px;
    padding: 20px;
}
.main .button.true{
    border-color: #2ecc71;
    color: #2ecc71;
}
.main .button.true:hover{
    background: #2ecc71 !important;
    color: #fff;
}
.main .button.false{
    border-color: #ec6d67;
    color: #ec6d67;
}
.main .button.false:hover{
    background: #ec6d67 !important;
    color: #fff;
}








.field.end{
    text-align: center;
}
.end .scoreboard{
    padding: 60px 0 50px 0;
    text-align: center;
    font-size: 30px;
    font-weight: 900;
}
.end .header{
    padding: 20px 0;
    font-size: 50px;
    color: #2cbeff;
}
.end .level{
    padding: 20px 0;
}
.end .counter{
    padding: 20px 0;
    font-size: 60px;
}
.end .text{
    padding: 20px 0;
}
.end .button.replay{
    margin: 0 auto;
    text-align: center;
    border-color: #f1c40f;
    background: #f1c40f;
    color: #fff;
}
.end .button.replay:hover{
    border-color: #f1c40f;
    color: #f1c40f;
}


.level1 .text,
.level2 .text,
.level3 .text,
.level4 .text{
    display: none;
    text-transform:none;
    letter-spacing: 0;
}
.level1 .level1,
.level2 .level2,
.level3 .level3,
.level4 .level4{
    display: block;
}
.level1 .level1,
.level1 .counter,
.level1 .level{
    color: #ec6d67;
}
.level2 .level2,
.level2 .counter,
.level2 .level{
    color: #f1c40f;
}
.level3 .level3,
.level3 .counter,
.level3 .level{
    color: #2cbeff;
}
.level4 .level4,
.level4 .counter,
.level4 .level{
    color: #2ecc71;
}










            
          
!
            
              $(document).ready(function () {

    var $levels = [1,2,3,4],
        $level = $levels[0],
        $count = 0,
        $first = $("#first"),
        $second = $("#second"),
        $result = $("#result"),
        $change,
        $toFirst,
        $toSecond,
        $toResult,
        $statusTime = 1,
        $resetTimer,
        $timer = 0,
        $buttonOrMouse = 1; //0-button,1-mouse
    
    var MathGame = {
        assignNumber:function (){
            $change = Math.floor((Math.random() * 4 ) + 1 );
            
            $toFirst = Math.floor((Math.random() * 10 ) + ($level === $levels[1] ? 10 : ($level === $levels[2] ? 20 : ($level === $levels[3] ? Math.floor((Math.random() * $count )) : 1))) );
            $toSecond = Math.floor((Math.random() * 10 ) + ($level === $levels[1] ? 10 : ($level === $levels[2] ? 20 : ($level === $levels[3] ? Math.floor((Math.random() * $count )) : 1))) );
            $toResult = (($change === 1 || $change === 2) ? ($toFirst+$toSecond) : Math.floor((Math.random() * 5 ) + ($toFirst+$toSecond+1) ) );

            $first.html($toFirst);
            $second.html($toSecond);
            $result.html($toResult);
        },
        onContinue:function (){
            $count++;
            (($count >= 20 && $count < 50) ? $level = $levels[1] : (($count >= 50 && $count < 70) ? $level = $levels[2] : ($count >= 70 ? $level = $levels[3] : $level = $levels[0] ) ) )
            $(".main #level").html($level);
            $(".main #counter").html($count);
            $("#time").css("width",+"0").removeClass("medium high");
            clearInterval($resetTimer);
            $timer = 0;
            $resetTimer = setInterval(function(){
                $timer++;
                $("#time").css("width",$timer+"%");
                $(".status").text( $timer );
                if( $timer >= 50 && $timer < 75 ){
                    $("#time").removeClass("high").addClass("medium");
                }else if( $timer >= 75 && $timer < 99 ){
                    $("#time").removeClass("medium").addClass("high");
                }else if( $timer >= 100 ){
                    clearInterval($resetTimer);
                    $timer = 0;
                    $statusTime = 0;
                    MathGame.toEnd();
                }
            },10);
        },
        toStart:function (){
            $("body").removeClass("start_ON end_ON").addClass("main_ON");
            $statusTime = 1;
            $count = 0;
            $level = $levels[0];
            clearInterval($resetTimer);
            $timer = 0;
        },
        toEnd:function (){
            $("#time").css("width",+"0").removeClass("medium high");
            clearInterval($resetTimer);
            $timer = 0;
            $("body").removeClass("start_ON main_ON").addClass("end_ON");
            $(".field.end").removeClass("level1 level2 level3 level4").addClass("level"+$level);
            $(".end #level").html($level);
            $(".end #counter").html($count);
            $(".main #level").html(1);
            $(".main #counter").html(0);
        }
    }


    
    
    $(".button").on("click", function (){
        var $that = $(this);
            
        if($that.hasClass("start") || $that.hasClass("replay")){
            MathGame.assignNumber();
            MathGame.toStart();
        }else if($that.hasClass("true") && $buttonOrMouse == 0){
            if( $toResult === ($toFirst+$toSecond) && $statusTime == 1 ){
                MathGame.onContinue();    
                MathGame.assignNumber();
            }else{
                MathGame.toEnd();
            }
        }else if($that.hasClass("false") && $buttonOrMouse == 0){
            if( $toResult !== ($toFirst+$toSecond) && $statusTime == 1  ){
                MathGame.onContinue();   
                MathGame.assignNumber();                
            }else{
                MathGame.toEnd();
            }
        }
        
        //$(".status").text( $count );
        
    });
    
    
    
    

    
    
    $("#withButton").on("click", function(){// button is active
        $("body").removeClass("withButton_ON").addClass("withMouse_ON");
        $buttonOrMouse = 1;
    });
    $("#withMouse").on("click", function(){// mouse is active
        $("body").removeClass("withMouse_ON").addClass("withButton_ON");
        $buttonOrMouse = 0;
    });
        
    $(".field.main").on({
        click:function(e){
            if( $buttonOrMouse == 1 && $("body").hasClass("main_ON") ){
                e.preventDefault();
                e.stopPropagation();
                if ($toResult === ($toFirst + $toSecond) && $statusTime == 1) {
                    MathGame.onContinue();
                    MathGame.assignNumber();
                } else {
                    MathGame.toEnd();
                }
            }
        },
        contextmenu:function(e){
            if( $buttonOrMouse == 1 && $("body").hasClass("main_ON") ){
                e.preventDefault();
                e.stopPropagation();
                if( $toResult !== ($toFirst+$toSecond) && $statusTime == 1  ){
                    MathGame.onContinue();   
                    MathGame.assignNumber();                
                }else{
                    MathGame.toEnd();
                }
            }
        }
    });
    
    
    
    
    
    


});
            
          
!
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.
Loading ..................

Console