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.

            
              <div class="container">
            <div class="row">
                <div class="col col-xs-12">
                    <div>
                    <span class="player1turn">player1turn</span>
                    <span class="player2turn">player2turn</span>
                    </div>
                    <div class="gameborder">
                        <div>
                        <span class="player1score">player1score<i></i></span>
                        <span class="player2score">player2score<i></i></span>
                        <span class="resetall">resetall</span>
                        </div>
                    <div class="gamebox">
                        <div class="playersentry">
                        <div class="players"></div>
                        <div class="playernumbers">
                            <span class="player1"></span>
                            <span class="player2"></span>
                        </div>
                        <div class="back-button"></div>
                        </div>
                        <div class="tictoebox">
                           <div class="boxes">
                                <div>
                                    <div id="1" class="box"></div>
                                    <div id="2"class="box"></div>
                                    <div id="3" class="box"></div>   
                                </div>
                                <div>
                                    <div id="4" class="box"></div>
                                    <div id="5" class="box"></div>
                                    <div id="6" class="box"></div>
                                </div>
                                <div>
                                    <div id="7" class="box"></div>
                                    <div id="8" class="box"></div>
                                    <div id="9" class="box"></div>
                                </div>
                            </div>
                            
                        </div>
                    </div>
                    
                    </div>
                    <div class="owinner"></div>
                </div>
            </div>
        
        </div>
            
          
!
            
              .gamebox{
    display: block;
    position: absolute;
    height: 400px;
    width:400px;
    background-color: rgb(27, 119, 56);
    /*border: solid rgba(240,180,135,1) 25px;*/
    margin-top: 30px;
    margin-left:30px;
    margin-bottom:20px;
    margin-right:20px;
    z-index: 2;
}
.gameborder{
    display: block;
    position: absolute;
    background-color: rgba(240,180,135,1);
    height: 470px;
    width: 460px;
    box-shadow: 1px 5px 20px 1px black;
    margin-top: 100px;
    margin-left:30%;
    margin-bottom:50px;
    margin-right:30%;
    z-index: 3;
}
.players{
    font-family: 'Kalam', cursive;
    text-align: center;
    color: azure;
    font-size: 40px;
    margin-left: 30px;
    margin-top: 60px;
    
}
.playernumbers{
    margin-top: 30px;
    text-align: center;
}
 .player1, .player2,.back-button,.choosex,.chooseo{
    font-family: 'Kalam', cursive;
    text-align: center;
    color: azure;
    font-size: 30px;
    margin-left: 10px;
    margin-right: 10px;
    padding: 2px 2px 2px 2px;
    cursor: pointer;
    
}
.back-button{
    margin-top: 50px;
}
.player1:hover, .player2:hover,.choosex:hover,.chooseo:hover{
    border: dashed white 2px;
    border-radius: 10px;
}

.boxes{
    margin-top: -150px;
    margin-left:10px;
    margin-bottom:1px;
    margin-right:0px;
    height: 400px;
    width: 400px;
    position: absolute;
    display: none;
    
    list-style: none;
}

.box{
    height: 110px;
    width: 110px;
    border: solid 1px black;
    display: inline-block;
    margin-top: 10px;
    margin-left: 1px;
    background-color: antiquewhite;
    color:azure;
    text-align: center;
    font-size: 90px;
    
    
}
.player1score{
    margin-top: 6px;
    margin-left: 4px;
    margin-right: 5px;
    font-size: 20px;
    font-family: 'Kalam', cursive;
    color:darkgrey;
    display: none;
}
.player2score{
    margin-top: -28px;
    margin-left: 140px;
    margin-right: 5px;
    font-size: 20px;
    font-family: 'Kalam', cursive;
    color:darkgrey;
    display: none;
}
.resetall{
    margin-top: -28px;
    margin-left: 300px;
    margin-right: 5px;
    font-size: 20px;
    font-family: 'Kalam', cursive;
    color:darkgrey;
    display: none;
    cursor: pointer;
}
i{
    margin-left: 3px;
}
.player1turn{
    display: none;
    position: absolute;
    font-family: 'Kalam', cursive;
    background-color: aqua;
    font-size: 30px;
    height: 40px;
    width: 200px;
    text-align: center;
    margin-top: 60px;
    margin-left:32%;
    margin-bottom:50px;
    margin-right:30%;
    padding:2px 2px 2px 2px;
}
.player2turn{
    display: none;
    position: absolute;
    font-family: 'Kalam', cursive;
    background-color:crimson;
    font-size: 30px;
    height: 40px;
    width: 200px;
    text-align: center;
    margin-top: 60px;
    margin-left:50%;
    margin-bottom:50px;
    margin-right:30%;
}
.owinner{
    display: none;
    position: absolute;
    height: 400px;
    width:400px;
    background-color: rgb(27, 119, 56);
    /*border: solid rgba(240,180,135,1) 25px;*/
    text-align: center;
    font-size: 50px;
    color: darkgray;
    margin-top: 140px;
    margin-left:380px;
    margin-bottom:20px;
    margin-right:20px;
    padding-top: 150px;
    z-index: 4;
}
            
          
!
            
              $(document).ready(function(){
   
    /*var playersentry=$('.playersentry').find('*');
    console.log(playersentry);*/
    var player;
    $('.players').text('How do you want to play?');
    $('.player1').text('One Player');
    $('.player2').text('Two Player');
    
    /*console.log(player.text());*/
    var player=$('.players').clone();
    var player1=$('.player1').clone();
    var player2=$('.player2').clone();
    var backbutton=$('.back-button').text();
    var countdraw=0;
    var player1score=0;
    var player2score=0;
    var playerflag;
    var turn;
    var playertwo=function(){
        $('.playernumbers').on("click",'.player2',function(){
               $('.players').text("Player 1 : Would you like X or O?");
                $('.player1').text("X");
                $('.player2').text('O');
                $('.back-button').text('back');
                $('.player1').addClass('choosex').removeClass('player1');
                $('.player2').addClass('chooseo').removeClass('player2');
                /*$('.player1').attr('class','choosex');
                $('.player2').attr('class','chooseo');*/
                            
    });
    }
    var back=function(){
        $('.back-button').on("click",function(){
            
           $('.players').text(player.text());
            $('.choosex').text(player1.text());
            $('.chooseo').text(player2.text());
            $('.back-button').text("");
            $('.choosex').addClass('player1').removeClass('choosex');
            $('.chooseo').addClass('player2').removeClass('chooseo');
            /*$('.choosex').attr('class','player1');
            $('.chooseo').attr('class','player2');*/
            
            
        });
    }
    var reset=function(){
        $('#1').text(" ");
        $('#2').text(" ");
        $('#3').text(" ");
        $('#4').text(" ");
        $('#5').text(" ");
        $('#6').text(" ");
        $('#7').text(" ");
        $('#8').text(" ");
        $('#9').text(" ");
        $('#1').off("click");
        $('#2').off("click");
        $('#3').off("click");
        $('#4').off("click");
        $('#5').off("click");
        $('#6').off("click");
        $('#7').off("click");
        $('#8').off("click");;
        $('#9').off("click");
        countdraw=0;
        console.log(playerflag);
        if(playerflag=='O'){
            player=0;
            turn=0;
           
        }
        else{
            player=1;
            turn=1;
           
        }
        gamebox();
    }
    var winner=function(){
        var box1=$('#1').text();
        var box2=$('#2').text();
        var box3=$('#3').text();
        var box4=$('#4').text();
        var box5=$('#5').text();
        var box6=$('#6').text();
        var box7=$('#7').text();
        var box8=$('#8').text();
        var box9=$('#9').text();
        //console.log("box1 "+box1);
        if((box1=="O" && box4=="O" && box7=="O") ||(box2=="O" && box5=="O" && box8=="O") ||(box3=="O" && box6=="O" && box9=="O")||
          (box1=="O" && box5=="O" && box9=="O")|| (box3=="O" && box5=="O" && box7=="O") ||
          (box1=="O" && box2=="O" && box3=="O") || (box4=="O" && box5=="O" && box6=="O") || (box7=="O" && box8=="O" && box9=="O")){
           console.log("O player "+player);
           console.log(playerflag);
            if(playerflag=='O'){
            if(player==0){
                player2score=player2score+1;
                $('.player2score i').text(player2score);
            }
            else{
                player1score=player1score+1;
                //var score=$('.player1score').text();
                $('.player1score i').text(player1score);
            }
            }
            if(playerflag=='X'){
              if(player==1){
                player2score=player2score+1;
                $('.player2score i').text(player2score);
            }
                else{
                player1score=player1score+1;
                //var score=$('.player1score').text();
                $('.player1score i').text(player1score);
            }
            }
            //
            //$('.player2turn').fadeOut(1000);
           //alert("O is winner");
            function loadOwinner(){
            $('.player2turn').css({"display":"none"});
            $('.owinner').text('O is winner');
            $('.owinner').fadeIn(1000);
            $('.owinner').fadeOut(3000);
            }
            loadOwinner();
           /* countdraw=0;*/
            reset();
        }
        else if ((box1=="X" && box4=="X" && box7=="X") ||(box2=="X" && box5=="X" && box8=="X") ||(box3=="X" && box6=="X" && box9=="X")|| (box1=="X" && box5=="X" && box9=="X")|| (box3=="X" && box5=="X" && box7=="X") ||
                (box1=="X" && box2=="X" && box3=="X") || (box4=="X" && box5=="X" && box6=="X") || (box7=="X" && box8=="X" && box9=="X")){
            console.log("X player "+player);
            console.log(playerflag);
            if(playerflag=='O'){
            if(player==0){
                player2score=player2score+1;
                //var score=$('.player1score').text();
                $('.player2score i').text(player2score);
                
            }
            else{
               player1score=player1score+1;
                $('.player1score i').text(player1score);
            }
            }
            if(playerflag=='X'){
            if(player==1){
                player2score=player2score+1;
                //var score=$('.player1score').text();
                $('.player2score i').text(player2score);
            }
            else{
                player1score=player1score+1;
                $('.player1score i').text(player1score);
            }
            }
           // $('.player2turn').fadeOut(1000);
           // alert("X is winner");
            function loadXwinner(){
            $('.player2turn').css({"display":"none"});
            $('.owinner').text('X is winner');
            $('.owinner').fadeIn(1000);
            $('.owinner').fadeOut(3000);
            }
            loadXwinner();
           // countdraw=0;
            reset();
        }
        else if(countdraw==9){
           // $('.player2turn').fadeOut(1000);
            //alert("its draw");
            function draw(){
            $('.player2turn').css({"display":"none"});
            $('.owinner').text('Its Draw');
            $('.owinner').fadeIn(1000);
            $('.owinner').fadeOut(3000);
            }
            draw();
            //countdraw=0;
            reset();
        }
        
        
    }
    var playerturn=function(turn){
        if(playerflag=='O'){
            if(turn==0){
                 $('.player2turn').fadeIn(1000);
                $('.player2turn').fadeOut(1000);
            }
            else{
                $('.player1turn').fadeIn(1000);
                $('.player1turn').fadeOut(1000);

            }
        }
        else if(playerflag=='X'){
            if(turn==1){
                 $('.player2turn').fadeIn(1000);
                $('.player2turn').fadeOut(1000);
            }
            else{
                $('.player1turn').fadeIn(1000);
                $('.player1turn').fadeOut(1000);

            }
        }
    }
    var gamebox=function(){
        //console.log(countdraw);
        
        $('.box').on("click",function(){
          playerturn(turn);
          if(player==0){
              countdraw=countdraw+1;
             // console.log("countdraw for O "+player+" "+countdraw);
              $(this).text('O');
              $(this).off("click");
              player=player+1;
              //this.disabled=disabled;
              turn=turn+1;
              winner();
          }  
          else if(player==1){
              countdraw=countdraw+1;
             // console.log("countdraw for X "+player+" "+countdraw);
              $(this).text('X');
              $(this).off("click");
              player=player-1;
              turn=turn-1;
              winner();
          }
        });        
    }
    
    
     var chooseO= function(){
        $('.playernumbers').on('click','.chooseo',function(){
            console.log("chooseo");
            $('.players').text("");
            $('.choosex').text("");
            $('.chooseo').text("");
            $('.back-button').text("");
            player=0;
            turn=player;
            $('.box').css({"background-color":"rgb(27, 119, 56)"});
            $('.gamebox').css({"background-color":"rgba(240,180,135,1)"});
            $('.boxes').css({"display":"flex"});
            $('.player1score').css({"display":"block"});
            $('.player2score').css({"display":"block"});
            $('.resetall').css({"display":"block"});
            //$('#horz1').css({"display":"block"});
            playerflag='O';
            $('.player1turn').fadeIn(1000);
            $('.player1turn').fadeOut(1000);
            gamebox();
        });
        
    }
    var chooseX= function(){
        $(document).on('click','.choosex',function(){
            console.log("choosex");
             $('.players').text("");
            $('.choosex').text("");
            $('.chooseo').text("");
            $('.back-button').text("");
            player=1;
            turn=player;
             $('.box').css({"background-color":"rgb(27, 119, 56)"});
            $('.gamebox').css({"background-color":"rgba(240,180,135,1)"});
           $('.boxes').css({"display":"flex"});
             $('.player1score').css({"display":"block"});
            $('.player2score').css({"display":"block"});
            $('.resetall').css({"display":"block"});
            playerflag='X';
            $('.player1turn').fadeIn(1000);
            $('.player1turn').fadeOut(1000);
            gamebox();
        });
        
    }
    var resetall=function(){
        $('.resetall').on("click",function(){
           history.go(0);
        })
    }
    playertwo();
    back();
    chooseO();
    chooseX();
    resetall();
});
            
          
!
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