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

              
                .base
  .screen
    h1#screen-text 0
    
  .funca
    button.btns.func#a
      h1#func0 +
    button.btns.func
      h1#func1 -
    button.btns.func
      h1#func2 *
    button.btns.func
      h1#func3 /
  
  .nums
    button.btns.btn#a
      h1#btn1 1
    button.btns.btn
      h1#btn2 2
    button.btns.btn
      h1#btn3 3
    button.btns.btn
      h1#btn4 4
    button.btns.btn#a
      h1#btn5 5
    button.btns.btn
      h1#btn6 6
    button.btns.btn
      h1#btn7 7
    button.btns.btn
      h1#btn8 8
    button.btns.btn#a
      h1#btn9 9
    button.btns.btn#zero
      h1#btn0 0
    button.btns.btn#dot
      h1#btndot .

  .funcsb
    button.btns.equals
      h1 =
    button.btns.clear
      h1 C
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Orbitron:400,500)

html, body
  height: 100%

html
  display: table
  margin: auto

body
  display: table-cell
  vertical-align: middle
  background-color: #818181

h1
  font-family: 'Orbitron', sans-serif
  color: black
  font-size: 2em
  margin: 0

.base
  width: 280px
  height: 380px
  background-color: #dfd8d0
  border: 4px solid #515151
  border-radius: 20px
  text-align: center
  
.screen
  width: 250px
  height: 45px
  border-radius: 8px
  background-color: #3e3e3e
  text-align: right
  align: center
  margin: auto
  margin-top: 20px
  margin-bottom: 20px
  
#screen-text
  margin-right: 5px

.btns
  border-radius: 8px
  border: none
  background-color: #3a3a3a
  margin: 0 4px 10px 8px
  height: 40px
  width: 50px
  box-shadow: 0px 3px 0px 0px #222121, inset -1px -3px 10px 1px #515151

#a
  margin-left: 2px
  
.btn
  
.funcsa
  display: inline-block
  width: 80px
  background-color: black
  
.func
  
.equals
  width: 115px
  margin-left: 2px
  
.clear,#zero
  width: 115px
              
            
!

JS

              
                var sum = [];
var funcs = [];
var newSum = "";
var result;
var oldResult = 99999999;

$(".btn").click(function(e){
  if (result !== null) {
    result = null;
    oldResult = 99999999;
  }
  var id = e.target.id;
  if (id !== "btndot") {
    console.log("btn = " + id);
    for (var i = 0; i < 10; i++) {
      if (id == "btn" + i) {
        newSum += i;
        console.log("newSum = " + newSum);
      }
    }
  }else if (newSum.indexOf(".") === -1) {
    if (newSum.length !== 0) {
      console.log("btn = " + ".");
      newSum += ".";
    }else{
      console.log("btn = " + "0.");
      newSum += "0.";
    }
    console.log("newSum = " + newSum);
  }
  updateScreen();
});

$(".func").click(function(e){
  if (oldResult !== 99999999) {
    sum.push(result);
  }
  var id = e.target.id;
  console.log(id);
  for (var i = 0; i < 4; i++) {
    if (id == "func" + i && newSum.length !== 0 || sum[0] === oldResult) {
      if (oldResult !== 99999999) {
        oldResult = 99999999;
      }
      var j;
      if (newSum.length !== 0) {
        sum.push(newSum); newSum = "";
      }
      console.log("func = " + i);
      funcs.push(getFunc(id));
      console.log("sum = " + sum);
      console.log("funcs = " + funcs);
    } else if (newSum.length === 0 && sum.length === funcs.length) {
      funcs[funcs.length-1] = getFunc(id);
    }
  }
  updateScreen();
});

$(".equals").click(function(e){
  if (sum.length !== 0) {
    if (newSum.length !== 0) {
      sum.push(newSum); newSum = "";
    }
    console.log("sum = " + sum);

    var olda = parseFloat(sum[0], 10);
    var newa;

    if (sum.length === funcs.length) {
      funcs.pop();
      console.log(funcs);
    }

    for (var i = 0; i < sum.length; i++) {
      newa = parseFloat(sum[i+1], 10);
      if (olda !== null && newa !== null && funcs[i] !== null) {
        if (funcs[i] === "+") {
          olda += newa;
        }else if (funcs[i] === "-") {
          olda -= newa;
        }else if (funcs[i] === "*") {
          olda *= newa;
        }else if (funcs[i] === "/") {
          olda /= newa;
        }
      }
    }
    result = olda;
    oldResult = result;
    sum = [];
    funcs = [];

    console.log("result = " + result);
  }
  updateScreen();
});

$(".clear").click(function(e){
  sum = [];
  newSum = "";
  funcs = [];
  oldResult = 99999999;
  result = null;
  updateScreen();
});

function getFunc(j) {
  if (j == "func0") {j = "+"} // add
      else if (j == "func1") {j = "-"}
      else if (j == "func2") {j = "*"}
      else if (j == "func3") {j = "/"}
  return j;
}

function isInt(i) {
  var notInt = ["+","-","*","/"];
  return notInt.indexOf(i) === -1;
}

function updateScreen() {
  if (result === null) {
    var j = "";
    for (var i = 0; i < sum.length; i++) {
      j += sum[i] + " " + funcs[i] + " ";
    }
    $("#screen-text").text(j + newSum);
  } else if (result === null && funcs.length !== 0) {
    $("#screen-text").text(result.toFixed(7) + " " + funcs[0]);
  } else {
    $("#screen-text").text(result.toFixed(7));
  }
}
              
            
!
999px

Console