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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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 id="container">
  <div id = "screen">
    <div class = "subscreen"> 
      <div id = "screen1">
        <div id = "screen1-inner"></div>
      </div>
    </div>
    <div class = "subscreen">
      <div id = "screen2">
      </div>
    </div>
  </div>
  <div id = "keypad">   
      <button id = "ac">AC</button>
      <button id = "del">DEL</button>
      <button id = "ans">ANS</button>
      <button id = "*" class = "operator notequals times">&times;</button>
      <button id = "7" class = "number seven notequals">7</button>
      <button id = "8" class = "number eight notequals">8</button>
      <button id = "9" class = "number nine notequals">9</button>
      <button id = "/" class = "operator notequals divide">&divide;</button>
      <button id = "4" class = "number four notequals">4</button>
      <button id = "5" class = "number five notequals">5</button>
      <button id = "6" class = "number six notequals">6</button>
      <button id = "+" class = "operator notequals plus">&plus;</button>
      <button id = "1" class = "number one notequals">1</button>
      <button id = "2" class = "number two notequals">2</button>
      <button id = "3" class = "number three notequals">3</button>
      <button id = "-" class = "operator notequals minus">&minus;</button>
      <button id = "0" class = "number zero notequals">0</button>
      <button id = "." class = "number notequals decimal">.</button>
      <button id = "(-)" class = "number negative">(&minus;)</button>
      <button id = "equals">&equals;</button>
    </div>
  </div>
</div>
              
            
!

CSS

              
                body, html {
  height : 100%;
  background: #2751f9;
  background: -webkit-linear-gradient(to right, #64b3f4, #2751f9);
  background: linear-gradient(to right, #64b3f4, #2751f9);
}

#container{
  height : 100%;
  padding : 6vh;
  min-width : 320px;
  margin : auto;
  border: none;
  box-shadow: 2px 2px 2px grey;
  background-color : #f7f4f4;
}

#screen {
  height : 30%;
  background-color : #d7f4d7;
  margin-bottom : 8vh;
  border-width: 2px;
  border : solid;
  border-bottom-color: #e8e9ed;
  border-right-color: #e8e9ed;
}

.subscreen {
  display : table;
  table-layout : fixed;
  overflow : hidden;
  width : 100%;
  padding : 1vw;
  font-size : 6vh;
  line-height : 100%;
  font-family: 'Orbitron', sans-serif;
  font-weight : bold;
  height : 50%;
  background-color: #d7f4d7;
  
}

#screen1 {
  display : table-cell;
  vertical-align : middle;
  text-overflow : ellipsis;
}

#screen1-inner {
  text-overflow : ellipsis;
  overflow : hidden;
  white-space : nowrap;
}

#screen2 {
  display : table-cell;
  vertical-align : middle;
  text-align : right;
}

#keypad {
  height : 60%;
  background-color : #f7f4f4;
  display : flex;
  flex-direction : row;
  flex-wrap : wrap;
  justify-content : space-between;
}

button {
  width : 15%;
  padding : 0;
  margin : 1%;
  box-shadow: 2px 2px 2px grey;
  border : none;
  font-weight : bold;
  background-color : #c1bfbf;
}

.seven, .eight, .nine {
  order : -3;
}

#ac, #del {
  order : -2;
}

.four, .five, .six{
 order : -1;
}

.times, .divide {
  order : 0;
}

#1, #2, #3 {
  order : 1;
}

.plus, .minus {
  order : 2;
}

.zero, .negative, .decimal {
  order : 3;
}

#ans, #equals {
  order : 4;
}

.number {
  background-color: #edeaea; 
}

#equals {
  background-color: #d8594e;
}

#empty {
  /*visibility : hidden;*/
}

button:hover {
  color : #2751f9;
}

#equals:hover {
  color : white;
}

button:active, #equals:active {
  box-shadow: 0 0 grey;
  transform: translateY(2px);
}

button:focus, #equals:focus {
  outline : 0;
}

@media (orientation : portrait) {  
  button {
    width : 20%;
    padding : 0;
    margin : 1%;
    box-shadow: 2px 2px 2px grey;
    border : none;
    font-weight : bold;
  }
  
  .number, #ac, #del, #equals, #ans, .decimal, #empty,.operator {
    order : 0;
  }
}

@media (min-width : 1200p
  xx){
  #container {
    width : 50%;
  }
}
              
            
!

JS

              
                $(document).ready(function() {
  var ans = undefined;
  var displayAns,
    ansString = "";

  function buttonPress() {
    if (/operator/.test($(this).attr("class")) === true) {
      if (/(\*|\+|\-|\/)$/.test(ansString[ansString.length - 1]) === true) {
        ansString = ansString.substr(0, ansString.length - 1);
      }
    }
    ansString += $(this).attr("id");
    $("#screen1-inner").text(ansString);
  }

  function round(value, decimals) {
    return Number(Math.round(value + "e" + decimals) + "e-" + decimals);
  }

  function standardForm() {
    displayAns = ans + "";
    console.log(displayAns);
    if (9 < displayAns.length < 25 && displayAns.indexOf("e") !== -1) {
      displayAns = displayAns.slice(0, 8) + "e" + (displayAns.length - 9);
      console.log(displayAns);
    }
    if (displayAns.indexOf("e") !== -1) {
      var numToBeRounded = displayAns.slice(0, displayAns.indexOf("e"));
      var expo = displayAns.slice(displayAns.indexOf("e") + 1);
      displayAns = round(numToBeRounded, 9) + " \xD7 10<sup>" + expo + "</sup>";
    } else {
      displayAns = round(ans, 9);
    }
  }

  function allClear() {
    ansString = "";
    ans = undefined;
    displayAns = "";
    $("#screen1-inner").text(ansString);
    $("#screen2").text(ansString);
    console.log("Cleared!");
  }

  function evaluate() { 
    if (ansString.length !== 0){          
      ansString = ansString.replace(/(--)/g, "+");   
      console.log(ansString);
      ans = ansString;
      ans = eval(ans); 
      console.log(ans);
      standardForm();  
      $("#screen2").html(displayAns);
    }
  }
  
  function del () {     
    ansString = ansString.slice(0, ansString.length - 1);   
    $("#screen1-inner").text(ansString);
    $("screen2").html("");
  }
  
  function negativeSign () {
    if (/(--)$/.test(ansString) === false){
      ansString += "-";
      $("#screen1-inner").text(ansString);
    }
  }
  
  function ansKey () {
    if (typeof ans === "number") {        
      ansString += ans;
      $("#screen1-inner").text(ansString);
    } else {
      $("#screen2").text("ans is not yet defined!");
    }
  }

  $(".notequals").on("click", buttonPress);
  $(".negative").on("click", negativeSign);
  $("#ans").on("click", ansKey);
  $("#ac").on("click", allClear);
  $("#equals").on("click", evaluate);
  $("#empty").on("click", standardForm);
  $("#del").on("click" , del);
});

              
            
!
999px

Console