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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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

              
                .container
  .calculatorBody
    input.calculatorScreen(disabled)
    .buttons
      .deleteButtons
        button.AC AC
        button.CE CE
      .numberButtons
        button 7
        button 8
        button 9
        button 4
        button 5
        button 6
        button 1
        button 2
        button 3
      .zeroDotButtons
        button.zero 0
        button.dot .
      .operationButtons
        button &divide
        button x
        button -
        button +
      button.equalsButton =
              
            
!

CSS

              
                body
  background-color: #222222
  
.calculatorBody
  display: flex
  flex-wrap: wrap
  
.buttons
  font-size: 0
  display: flex
  flex-wrap: wrap
  
  button
    font-size: 40px
    padding: 10px

input, button
  min-width: 48px
  min-height: 48px
  margin: 0
  font-size: 30px
  border: 1px solid #00FFFF
  color: #00FFFF
  background: linear-gradient(#111111, #040404)
  
input
  width: 100%
  padding-left: 15px
  padding-right: 10px
  disabled: true
  
button
  min-width: 80px
  width: 33.3%
  
.deleteButtons
  order: -2
  width: 100%
  button
    width: 50%
    
.numberButtons
  width: 100%
  order: -1
  
.zeroDotButtons
  width: 100%
  button
    width: 33.3%
  button.zero
    width: 66.6%
    
.operationButtons
  width: 66.6%
  button
    width: 50%
    
@media screen and (min-width: 400px)
  .container
    width: 400px
    margin-left: auto
    margin-right: auto
              
            
!

JS

              
                $("document").ready(function(){
  var numbersInput = function(button){
    var prevVal = $(".calculatorScreen").val();
    $('.calculatorScreen').val(prevVal + $(button).text());
  }
  var placeEvalSigns = function(input){
    var result = input;
    result = result.replace(/x/g, '*');
    result = result.replace(/÷/g, '/')
    return result;
  }
  var lastInputIsSign = function(){
    var input = $(".calculatorScreen").val();
    var isSign = function(char){
      var signs = ["+", "-", "x", "÷", "."];
      for(var i=0; i < signs.length; i++){
        if(signs[i] === char){
          return true;
        }
      }
      return false;
    }
    if(isSign(input.slice(-1))){
      return true;
    } else {
      return false;
    }
  }
  
  $(".numberButtons button").click(function(){
    var buttonClicked = $(this);
    numbersInput(buttonClicked);
  });
  $(".zero").click(function(){
    var buttonClicked = $(this);
    numbersInput(buttonClicked);
  });
  $(".dot").click(function(){
    var buttonClicked = $(this);
    var currentInput = $('.calculatorScreen').val();
    if(!currentInput == '' && !lastInputIsSign()){
    numbersInput(buttonClicked);
    }
  });
  $(".operationButtons button").click(function(){
    var buttonClicked = $(this);
    if(!lastInputIsSign() && !$(".calculatorScreen").val() == ''){
     numbersInput(buttonClicked);
    }
  });
  $(".AC").click(function(){
    $(".calculatorScreen").val('');
  });
  $(".CE").click(function(){
    var prevVal = $(".calculatorScreen").val();
    $(".calculatorScreen").val(prevVal.slice(0, -1));
  });
  $(".equalsButton").click(function(){
    var prevVal = $('.calculatorScreen').val();
    var formatedInput = placeEvalSigns(prevVal);
    var result = eval(formatedInput).toFixed(2);
    if(result == 'Infinity'){
      result = '';
    }
    if(!lastInputIsSign() && !prevVal == ''){
      $('.calculatorScreen').val(result);
    }
  });
});
              
            
!
999px

Console