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 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

              
                <!-- All the HTML code, only that, must be entered here -->

<div id="calcolatrice">

  <textarea id="display"></textarea>
  <div id="pulsantiera">

    <input type="button" value="sin" class="funzione sin">
    <input type="button" value="cos" class="funzione cos">
    <input type="button" value="tan" class="funzione tan">
    <input type="button" value="atn" class="funzione atn">

    <input type="button" value="(" class="parentesi">
    <input type="button" value=")" class="parentesi">
    <input type="button" value="←" class="rimuovi" >
    <input type="reset"  value="C" class="resetta">

    <input type="button" value="1">
    <input type="button" value="2">
    <input type="button" value="3">
    <input type="button" value="+" class="operatore addizione">

    <input type="button" value="4">
    <input type="button" value="5">
    <input type="button" value="6">
    <input type="button" value="-" class="operatore sottrazione">

    <input type="button" value="7">
    <input type="button" value="8">
    <input type="button" value="9">
    <input type="button" value="×" class="operatore moltiplicazione">

    <input type="button" value="0">
    <input type="button" value="." class="separatore">
    <input type="button" value="=" class="risolvi">
    <input type="button" value="÷" class="operatore divisione">

  </div>
</div>
              
            
!

CSS

              
                /*-- All the CSS formatting should be put here --*/

* {
  box-sizing: border-box;
}

body {
  background: #e4dddb;
}

#calcolatrice {
  width: 350px;
  padding: 7px;
  border-radius: 6px;
  background: #445066;
  box-shadow: 2px 2px 4px rgba(0,0,0,.5);
}

#display {
  width: 100%;
  height: 3.5em;
  resize: none;
  margin: 5px 0 10px;
  padding: 4px 4px 2px;
  font: 24px/1 "Lucida Console", Monaco, monospace;
  text-align: right;
  border: 1px solid #112e13;
  border-radius: 4px;
  color: #010d00;
  background: #a5cb8d;
  overflow-y: auto;
}

#display::-moz-selection {
  color: #062;
  background: #9bff9b;
}
#display::selection {
  color: #062;
  background: #9bff9b;
}

#pulsantiera {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-around;
  padding: 10px;
  border-radius: 3px;
  background: #e0e1e9;
}

#pulsantiera input {
  width: calc(90% / 4);
  margin: 3px 0;
  padding: 5px;
  font: bold 20px/1.2 "Arial Black", Gadget, sans-serif;
  text-align: center;
  border: 1px solid #555;
  border-radius: 4px;
  cursor: pointer;
  box-shadow: inset 0 0 20px rgba(0,0,0,0);
  transition: .3s;
}

#pulsantiera input:hover {
  border-color: #fff;
  box-shadow: inset 0 -40px 5px rgba(0,0,0,.15);
  transition: .1s;
}

/* - Buttons colors - */

#pulsantiera input         { background: #7da5d6; color: #fff;    }
#pulsantiera .resetta      { background: #db3b3b;                 }
#pulsantiera .rimuovi      { background: #c7c8c2; color: #cc2e38; }

#pulsantiera .operatore    ,
#pulsantiera .separatore   ,
#pulsantiera .parentesi    { background: #c7c8c2;                 }

#pulsantiera .risolvi      { background: #21b476;                 }
#pulsantiera .funzione     { background: #cc6c4b;                 }

              
            
!

JS

              
                /*-- All the JavaScript actions should be put here --*/

window.onload = inizializza;

function inizializza(){
  display.focus();

  display.onkeydown = function(e){

    // When I press "send", go to elaborate
    if(e.keyCode == 13){
      risolviEspressioneDisplay();
      e.preventDefault();
    }
  }

  var tasti = document.querySelectorAll('#pulsantiera>input');
  var i = tasti.length;
  while(i--){
    tasto = tasti[i]
    classe = tasto.classList;

    if (classe.contains('funzione'))       tasto.onclick = function(){inserisciFunzione(this.value);};
    else if (classe.contains('risolvi'))   tasto.onclick = risolviEspressioneDisplay;
    else if (classe.contains('rimuovi'))   tasto.onclick = rimuoviUltimoCarattere;               
    else if (classe.contains('resetta'))   tasto.onclick = function(){visualizza('');};               
    else                                   tasto.onclick = function(){aggiungiAlDisplay(this.value);};

  };
}

function aggiungiAlDisplay(valore){
  visualizza(display.value + valore);
}

function rimuoviUltimoCarattere(){
  visualizza(display.value.slice(0, -1));
}

function inserisciFunzione(nomeFunzione){
  visualizza(' '+nomeFunzione+'('+display.value+')');
}

function risolviEspressioneDisplay(){
  var espressione = sostituisciValoriSpeciali(display.value);
  visualizza(eval(espressione));
}

function sostituisciValoriSpeciali(espressione) {
  var coppieValori = [
    ['sin', 'Math.sin'  ]
    ,['cos', 'Math.cos'  ]
    ,['tan', 'Math.tan'  ]
    ,['atn', 'Math.atan' ]
    ,['×'  , '*'         ]
    ,['÷'  , '/'         ]
  ]
  for (var i = 0; i < coppieValori.length; i++)
    espressione = espressione.replace(new RegExp(coppieValori[i][0],"g"), coppieValori[i][1]);
  return espressione;
};

function visualizza(valore){
  display.value = valore;
  spostaCursoreAllaFine(display);
}

// Scroll and place the cursor at the end of the textarea
function spostaCursoreAllaFine(el){
  el.focus();
  el.scrollTop = el.scrollHeight
}
              
            
!
999px

Console