cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

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.

Quick-add: + add another resource

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.

Quick-add: + add another resource

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.

            
              <div class="container">
<div class="cal-body gradient">
<div class="header">
</div>  
<div class="lcd">
 <div class="num-input">
   <span>0</span>
  </div>  
</div>
<div class="row">
 <div class="col-md-12">
   <button>C</button>
   <button>CE</button>
  </div>
 </div>
<div class="row">
  <div class="col-md-12">
   <button>7</button>
   <button>8</button>
   <button>9</button>
   <button>&divide;</button>
  </div>
 </div>
<div class="row">
  <div  class="col-md-12">
   <button>4</button>
   <button>5</button>
   <button>6</button>
   <button>X</button>
  </div>
  </div>
  <div class="row">
  <div  class="col-md-12">
   <button>1</button>
   <button>2</button>
   <button>3</button>
   <button>-</button>
  </div>
  </div>
   <div class="row">
  <div  class="col-md-12">
   <button>0</button>
   <button>.</button>
   <button>+</button>
   <button class="equal">=</button>
  </div>
  </div>   
  </div>
</div>
</div>  
            
          
!
            
              @font-face {
  font-family: "digital-7";
  src: url("http://schulzmarcel.de/x/fonts/digital-7_mono.ttf");
}
body{
  background-color:#4E4E4E;
}
.cal-body{
  padding:0px 10px;
  height:350px;
  width:300px;
  border-bottom:20px #535353;
  background-image: -webkit-gradient(linear, 0 0, 13 1614, from(#5b5b5b), color-stop(0.032, #535353), to(#1f1f1f));
background-image: -webkit-linear-gradient(270.4614801901714deg, #5b5b5b, #535353 3.2%, #1f1f1f);
background-image: -moz-linear-gradient(270.4614801901714deg, #5b5b5b, #535353 3.2%, #1f1f1f);
background-image: -o-linear-gradient(270.4614801901714deg, #5b5b5b, #535353 3.2%, #1f1f1f);
background-image: linear-gradient(179.53851980982859deg, #5b5b5b, #535353 3.2%, #1f1f1f);
  padding-top:35px;
  border-bottom-left-radius: 3px;
  border-bottom-right-radius: 3px;
  margin:0 auto;
  box-shadow: 5px 5px 15px #DCDCDC;
  border: 1px solid #535353;
  border-radius:10px;
}
.lcd{
  background-color:#BFD0BE;
  height:40px;
  width:200px;
  margin:0 auto;
  margin-bottom:20px;
  border-radius: 7px;
  overflow: hidden;
  
 
}
.gradient{
   box-shadow: inset 0px 0px 56px -5px rgba(0,0,0,0.98);
   -webkit-box-shadow: inset 0px 0px 56px -5px rgba(0,0,0,0.98);
  -moz-box-shadow: inset 0px 0px 56px -5px rgba(0,0,0,0.98);
  box-shadow: inset 0px 0px 56px -5px rgba(0,0,0,0.98);
  border: 1px solid #000;
  background-image:
    radial-gradient(
      #4A4A4A,
      #505050
    );
}
button{
  width:22%;
  padding:5px;
  margin:5px 2px;
  background-color:#EEEEEE;
  border-radius: 8px;
}
.num-input{
  font-family:digital-7;
  margin:0 auto;
  line-height: 1.7;
  font-size:1.5em;
  float:right;
 }
.equal{
  background-color:#EDA54B;
  color:#fff;
  font-size:10px;
}
button:hover { 
    border: 2px solid #343434;
}

            
          
!
            
              $(function() {
  var numInput = [];
  var operationPressed = 0;
  var selectedTimes = null;
  var operation = null;
  var sum = 0;
  var zero = null;
  var reset = false;
  var currentValue = 0;
  var val1 = 0;
  var counter = 0;
  var answerDisplayed = false;
  var previousVal = 0;
  var currentVal = 0;
  var decimalCounter = 0;
  var calculated = false;
  
  var zeroCheck = function(){
 numInput.forEach(function(value,key){
   console.log(value);
   if(value === 0){ 
     zero = true; 
     
   }  
 });  
 return zero;       
}; 
  

  var checkDecimalCount = function() {
      var regexp = /['.']/gi;
      var matches_array = $('.num-input').text().match(regexp);
       console.log(matches_array);
      if(matches_array!== null){
         return matches_array.length;  
      }
      return 0;
  }
  var checkForZero = function() {
    var initialValue = parseFloat($('.num-input').text());
    if (operation != null && reset === true) {
      console.log('Counter is being reset to Zero');
       decimalCounter = 0;
      console.log('reset to zero');
      counter = 0;
      reset = false;
      if($('.num-input').text() === '.'){
          $('.num-input').text('.');
          console.log('In check For Zero . has been added');
      } else{
      $('.num-input').text('');
      }
    }
    if (initialValue === 0) {
      $('.num-input').text('');
      console.log('the intinal value is '+initialValue);
    }
    console.log(decimalCounter);
    return initialValue;
  };
  var clearArr = function() {
    while (numInput.length != 0) {
      numInput.pop();
    }
    sum = 0;
   console.log(numInput);
  }
  var operationCheck = function(){
    console.log(operation);
    console.log(numInput);
   if(numInput.slice(-1).pop() != operation){
      numInput.pop();
      numInput.push(operation);
   }
   console.log(numInput);
  }
  var checkDecimalPlace = function(){
      var regexp = /['.']/gi;
      var matches_array = numInput.join('').match(regexp);
      if(matches_array!== null){
         if(matches_array.length>counter) 
           return false;
          }
       
      return true;
   
  }
  var calculate = function() {
      var zero =  zeroCheck();
    
       console.log('length of zero');
       // numInput = numInput.filter(Boolean);
    
       console.log(numInput);
      $('.num-input').text('');
      $('.num-input').text(eval(numInput.join('')));
     
       clearArr();
    console.log(numInput);
  }
  var checkForLastNumber = function(){
      console.log(numInput.slice(-1).pop());
     if(isNaN(numInput.slice(-1).pop())){
        console.log('do not calculate the answer'); 
        numInput = numInput.filter(Boolean);
      return false;
      } else{
        return true;
      }
  }

  $('button').click(function() {

   if($(this).text() === '.'){
      decimalCounter++;
      }
   
    
    switch ($(this).text()) {
      case 'CE':
        $('.num-input').text('');
        $('.num-input').text('0');
        break;
      case '+':
         operation = '+';
        operationPressed++;
        if(!(isNaN(parseFloat($('.num-input').text())))){
        numInput.push(parseFloat($('.num-input').text()));
        }
        if(operationPressed === 1){
         numInput.push('+');
        } 
         $('.num-input').text('+');
         reset = true;
       operationCheck();
        break;
      case '-':
       operation = '-';
       operationPressed++;
        if(!(isNaN(parseFloat($('.num-input').text())))){
        numInput.push(parseFloat($('.num-input').text()));
        }
        if(operationPressed === 1){
         numInput.push('-');
        }
        $('.num-input').text('-');
        reset = true;
        operationCheck();
        break;
      case 'X':
        operation = '*';
        operationPressed++;
        if(!(isNaN(parseFloat($('.num-input').text())))){
        numInput.push(parseFloat($('.num-input').text()));
        }
        if(operationPressed === 1){
         numInput.push('*');
        }
        $('.num-input').text('*');
        reset = true;    
        operationCheck();
        break;
      case '÷':
        operation = '/';
         operationPressed++;
       if(!(isNaN(parseFloat($('.num-input').text())))){
        numInput.push(parseFloat($('.num-input').text()));
        }
        if(operationPressed === 1){
         numInput.push('/');
        }
        $('.num-input').text('÷');
        reset = true;
        operationCheck();
        break;
      case '.':
     var count = checkDecimalCount();
     console.log(count);
     if(count < 1){
     console.log( $('.num-input').text() === '0')
      if( $('.num-input').text().trim() === '0'){
        $('.num-input').text('');
      }
      if($('.num-input').text().trim() === '+'){
        $('.num-input').text('');
      }
      $('.num-input').append($(this).text());
     }
      break;  
      case 'C':
        operation = null;
        counter = 0;
        currentVal = 0;
        previousVal = 0;
        clearArr();
        $('.num-input').text('');
        $('.num-input').append(0);
        break;
      case '=':
       console.log(numInput);
        numInput.push(parseFloat($('.num-input').text()));
        console.log(parseFloat($('.num-input').text()));
      var checkObj =  checkForLastNumber();
       if(checkObj){ 
       calculate();
       calculated = true;  
       }else{
         
       } 
        break;
      default:
        operationPressed = 0;
        var Zero = checkForZero();
        if(calculated == false){
        $('.num-input').append($(this).text());
        }else{
           $('.num-input').text('');
          $('.num-input').append($(this).text());
          calculated = false;
        }  

    }

  });

});
            
          
!
999px
Loading ..................

Console