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.

            
              
<h1 class="text-center" id="java">JavaScript Calculator</h1>
<div class="container">
  <div class="row">
    <div class="col-xs-3">
    </div>
    <div class="col-xs-6 well calc" >      <!--  Display  box with  current number and current equation-->
      <div class="jumbotron">
        <p class="text-right" id="inputNum">
          Let's Compute
        </p>
        <p class="text-right" id="currEquation">
          waiting...
        </p>
      </div>
      <!--All the buttons for  calculator-->
      <div class="row">
        <div class="col-xs-3">
          <div class= "key clearkey btn-default well text-center calc-btn-default" id="AC">
            <span>
              AC
            </span>
            </div>
        </div>
        <div class="col-xs-3">
           <div class= "key opkey btn-default well text-center calc-btn-prim" id="/">
            <span>
              ÷
            </span>
            </div>
        </div>
        <div class="col-xs-3">
         <div class= "key numkey btn-default well text-center calc-btn-prim" id=".">
            <span>
              .
            </span> 
        </div>
  
        </div>
        <div class="col-xs-3">
          <div class= "key opkey btn-default well text-center calc-btn-prim" id="+">
            <span >
              +
            </span>
        </div>
        </div>
      </div>
         <div class="row">
        <div class="col-xs-3">
          <div class= "key numkey btn-default well text-center calc-btn-num" id="7">
            <span >
              7
            </span>
        </div>
        </div>
        <div class="col-xs-3">
         <div class= "key numkey btn-default well text-center calc-btn-num" id="8">
            <span>
              8
           </span>
        </div>
        </div>
        <div class="col-xs-3">
          <div class= "key numkey btn-default well text-center calc-btn-num" id="9">
            <span>
              9
            </span>
        </div>
  
        </div>
        <div class="col-xs-3">
          <div class= "key opkey btn-default well text-center calc-btn-prim" id="-">
            <span>
              -
            </span>
        </div>
        </div>
      </div>
         <div class="row">
        <div class="col-xs-3">
         <div class= "key numkey btn-default well text-center calc-btn-num" id="4">
            <span>
              4
           </span>
        </div>
        </div>
        <div class="col-xs-3">
          <div class= "key numkey btn-default well text-center calc-btn-num" id="5">
            <span>
              5
            </span>
        </div>
        </div>
        <div class="col-xs-3">
          <div class= "key numkey btn-default well text-center calc-btn-num" id="6">
            <span>
              6
            </span>
        </div>
  
        </div>
        <div class="col-xs-3">
          <div class= "key opkey btn-default well text-center calc-btn-prim" id="*">
            <span>
              x
            </span>
        </div>
        </div>
      </div>
         <div class="row">
        <div class="col-xs-3">
         <div class= "key numkey btn-default well text-center calc-btn-num" id="1">
            <span>
              1
            </span>
        </div>
        </div>
        <div class="col-xs-3">
         <div class= "key numkey btn-default well text-center calc-btn-num" id="2">
            <span>
              2
           </span>
        </div>
        </div>
        <div class="col-xs-3">
          <div class= "key numkey btn-default well text-center calc-btn-num" id="3">
            <span>
              3
            </span>
        </div>
  
        </div>
        <div class="col-xs-3">
           <div class= "key opkey equal btn-default well text-center calc-btn-default" id="=">
            <span>
              =
            </span>
        </div>
        </div>
      </div>
      <div class="row">
        <div class="col-xs-12">
        <div class= "key numkey btn-default well text-center calc-btn-num" id="0">
          <span>
            0
          </span>
          </div>
        </div>
      </div>
    </div>
    
    <div class="col-xs-3">

    </div>
    
  </div>

</div>
<div class="container">
  <div class="row">
    <div class="col-xs-12">
<h3 class="text-center"> created by <a href="https://codepen.io/Mykj23">Mykj23</a></h3>
    </div>
  </div>
</div>


            
          
!
            
              body{
  background-color:rgba(25, 124, 152,1)
}
#java{
  border:none;
    font-family: 'Ultra', serif;
}
.calc{
  font-family: 'Slabo 13px', serif;
  font-size:20px;
  top:50px;
  background-color:rgba(40, 65, 166,1);
  border:solid;
   border-color:rgba(0,0,0,.6);
}
.jumbotron{
 margin-top:10px;
  font-weight:bold;
 background-color:rgba(255, 187, 118,1);
  border:solid;
  border-color:rgba(0,0,0,.5)
}
.calc-btn-default{
  background-color:rgba(244, 139, 33,1);
}
.calc-btn-prim{
  background-color:rgba(25, 124, 152,1);
}
.calc-btn-num{
  background-color:rgba(244, 181, 33,1);
}
.text-center{
  border:solid;
  border-top:none;
  border-left:none;
  border-color:rgba(0,0,0,.7)
}
h3.text-center{
  font-family: 'Ultra', serif;
  font-size:12px;
  border:none;
  padding-top:20px;
   
}

 a{
      color:rgba(244, 139, 33,1)
  }
a:hover{
  
    color:rgba(244, 181, 33,1)
}


            
          
!
            
              /*
Work on :
-to chain must hit  opkey twice
*/
$(document).ready(function() {
    var firstNum= []
    var secNum= []
    var equation= ""
    var result=0
    var input={
      numOne:null,
      numTwo:null,
      op:null
    }
    
   
   
    $(".key").on("click", function(){
    var value=this.id
      if ($(this).hasClass("opkey")){
        if(input.op===null && firstNum.length!==0){
          input.op=value
          input.numOne=firstNum.join("")
           $("#inputNum").html(input.op)
        } else if (input.numOne!==null && secNum.length!==0 && input.op!==null){
          input.numTwo=secNum.join("")
          
        }
        
    
    } else if ($(this).hasClass("numkey") && input.numOne===null){
        firstNum.push(value)
      
      $("#inputNum").text(firstNum.join(""))
    }  else if ($(this).hasClass("numkey") && input.numOne!==null){
   secNum.push(value)
       $("#inputNum").text(secNum.join(""))
    }  
      if($(this).hasClass("clearkey")){
      firstNum= []
    secNum= []
    equation= ""
    result=0
    input.numOne=null
     input.numTwo=null
     input.op=null
      
    $("#inputNum").html("Let's Compute")
      $("#currEquation").html("waiting...")
    }
    
      if(input.numOne!==null && input.numTwo!==null ){
        var make
        if(input.op!=="=" && input.op!=="AC"){
         make= input.numOne + input.op +input.numTwo
          $("#currEquation").text(make + value)
          result=eval(make)
          firstNum=[result]
          input.op=result
          input.op=null
          input.numTwo=null
          secNum=[]
          $("#inputNum").text(result)
          
        }  else if (input.op==="=" && input.op!=="AC"){
          make= input.numOne + input.op +input.numTwo
          
          result=eval(make)
          input.numOne=null
          input.op=null
          input.numTwo=null
          secNum=[]
          firstNum=[]
          equation=(make + value)
          $("#inputNum").text(result)
          $("#currEquation").text(equation)
          equation=""
        }
          
        
    
        
        
      }
     
    });
  
 
  
  
   });

            
          
!
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