Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

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

              
                <div class="calculator container-md py-1">
  <!--<div class="row px-1">
    <p class="col-12 text-end result">01234567890</p>
  </div>-->
  <div class="row px-1">
    <p id="display" class="col-12 text-end current">0</p>
  </div>
  <div class="row px-1">
   <button id="clear" class="col-6 btn btn-danger">AC</button>
   <button id="divide" class="col-3 btn btn-secondary ">/</button>
   <button id="multiply" class="col-3 btn btn-secondary">*</button>
  </div>
  <div class="row px-1">
    <button id="seven" class="col-3 btn btn-primary">7</button>
    <button id="eight" class="col-3 btn btn-primary" >8</button>
    <button id="nine" class="col-3 btn btn-primary">9</button>
    <button id="subtract" class="col-3 btn btn-secondary">-</button>
  </div>
  <div class="row px-1">
    <button id="four" class="col-3 btn btn-primary">4</button>
    <button id="five" class="col-3 btn btn-primary" >5</button>
    <button id="six" class="col-3 btn btn-primary">6</button>
    <button id="add" class="col-3 btn btn-secondary">+</button>
  </div>
  <div class="row px-1">
    <div class="col-9">
      <div class="row">
        <button id="one" class="col-4 btn btn-primary">1</button>
        <button id="two" class="col-4 btn btn-primary" >2</button>
        <button id="three" class="col-4 btn btn-primary">3</button>
      </div>
      <div class="row">
        <button id="zero" class="col-8 btn btn-primary">0</button>
        <button id="decimal" class="col-4 btn btn-info">.</button>
      </div>
    </div>
    <button id="equals" class="col-3 btn btn-success">=</button>
  </div>
</div>
              
            
!

CSS

              
                
@import 'https://fonts.googleapis.com/css?family=Share+Tech+Mono';
/*@font-face {font-family: "Digital2"; src: url("//db.onlinewebfonts.com/t/2d6cb0ab2a3bb39c8b6746a6aab1db0c.eot"); src: url("//db.onlinewebfonts.com/t/2d6cb0ab2a3bb39c8b6746a6aab1db0c.eot?#iefix") format("embedded-opentype"), url("//db.onlinewebfonts.com/t/2d6cb0ab2a3bb39c8b6746a6aab1db0c.woff2") format("woff2"), url("//db.onlinewebfonts.com/t/2d6cb0ab2a3bb39c8b6746a6aab1db0c.woff") format("woff"), url("//db.onlinewebfonts.com/t/2d6cb0ab2a3bb39c8b6746a6aab1db0c.ttf") format("truetype"), url("//db.onlinewebfonts.com/t/2d6cb0ab2a3bb39c8b6746a6aab1db0c.svg#Digital2") format("svg"); }*/

* {
  box-sizing: border-box;
}

body {
  background-color: #A7D6BE;
  height: 90vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.calculator {
  background-color: black;
  max-width: 350px;
}

.btn {
  border-radius: 0px;
  border: 1px solid black;
  padding: 20px;
}

p {
  color: white;
  font-family: Digital2;
  font-size: 20px;
  margin: 0;
}

.result {
  font-size: 1rem;
  color: #E89222;
}

.btn-info {
  background-color: #0D6EFD;
  color: white;
}
              
            
!

JS

              
                



$(document).ready(function(){
  
  let op = false;
  let putDecimal = true;
  
  $("#clear").click(function(){
    $("#display").html("0");
    putDecimal = true;
  });
  
  // jQuery para introducir numeros en el display, tambien está implementado el que no haya numeros que empiecen por multiples zeros
  $(".btn-primary").click(function(){
   if($("#display").html() === "0" | op){
    $("#display").html($("#" + this.id).html());
    op = false;
   } else {
    $("#display").append($("#" + this.id).html());
   }
    
   });
  
 //Bloque de codigo para las operaciones, implementado para que solo se pueda poner un simbolo despues de un numero
 // 1- Si introducimos un simbolo despues de otro u otros, este ultimo sustituirá al resto
 // 2- Excepto si es un -, el cual se podrá añadir, pero solo una vez.
  $(".btn-secondary").click(function(){
   let x = $("#display").html();
   let simbolo = $("#" + this.id).html();
   let patternS = /^.*\d$/;
   if(patternS.test(x)){
    $("#display").append(simbolo);
     op = false;
     putDecimal = true;
   } else {
     if(simbolo !== "-"){
      x = x.replace(/^(.*\d)(\D{1,2})$/,"$1" + simbolo);
      $("#display").html(x);
     } else if (/^.*\d\D$/.test(x)) $("#display").append(simbolo);
   }
   
   });
  
   //Bloque de codigo para el resultado
  $("#equals").click(function(){
   let x = $("#display").html();
   console.log('operation', document.getElementById('display').innerText)
   $("#display").html(eval(x));
   op = true;
   putDecimal = true;
  });
  
  //Bloque de codigo para el punto decimal
  // 1 - no se puede poner mas de 1 en un numero
  // 2 - Despues de un numero se pone normal
  // 3 - Si se pone despues de un simbolo se añade un cero antes del punto decimal
 $("#decimal").click(function(){
   if(putDecimal){
     let y = $("#display").html(); 
     let patternD = /.*\d$/;
     if(patternD.test(y)){
      $("#display").append(".");
      putDecimal = false;
     } else {
      $("#display").append("0.");
     }
   }
  });
 
  
});











              
            
!
999px

Console