123

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.

            
              .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 =
            
          
!
            
              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
            
          
!
            
              $("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
🕑 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.

Console