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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

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.

HTML

            
              <html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Annotatable Calculator</title>
</head>
<body>
  <h1>Annotatable Calculator</h1>
  <div class="wrapper">
    <div class="dash">
      <form id = "io">
        <input type="text" id = "annotation" placeholder="Optional annotation">
        <input type="text" id = "formula" placeholder="Press Enter to Calculate">
      </form>
      <button class="clear" id="clearAnnotation">Clear annotation</button>
      <button class="clear" id="clearFormula">Clear formula</button>
      <button class="clear" id="clearHistory">Clear history</button>
    </div>
    <div class="keyboard">
      <div class="row">
        <button class="num">7</button>
        <button class="num">8</button>
        <button class="num">9</button>
        <button class="oper">/</button>
      </div>
      <div class= "row">
        <button class="num">4</button>
        <button class="num">5</button>
        <button class="num">6</button>
        <button class="oper">*</button>
      </div>
      <div class="row">
        <button class="num">1</button>
        <button class="num">2</button>
        <button class="num">3</button>
        <button class="oper">-</button>
      </div>
      <div class="row">
        <button id="ce">CE</button>
        <button class="num">0</button>
        <button class="oper">**</button>
        <button class="oper">+</button>
      </div>
      <div class="row">
        <button id="ac">AC</button>
        <button class="num">.</button>
        <button id="sign">±</button>
        <button class="equal">=</button>
      </div>
    </div>
    <div id="history">
      <div id="historyTitle"><h3>History</h3></div>
      <div id="historyContent"></div>
    </div>
  </div>
  <br>
  <br> 
  <footer>Product by Zack Light</footer>
</body>
</html>
            
          
!

CSS

            
              body {
 font-family: Arial, sans-serif;
 text-align: center;
}

a {
  text-decoration: none;
}

button:active {
  transform: translate(0px, 3px);
  box-shadow: none;
}

.clear, input{
  display: block;
  margin-left: 2px;
  margin-bottom: 5px;
  font-size: 1em;
}

.clear {
   width: 200px;
}

.keyboard button {
    display: inline-block;
    text-decoration: none;
    font-weight: bold;
    color: #fff;
    background-color: black;
    font-size: 1.5em;
}

#ac, #ce, .keyboard .equal {
  background-color: maroon;
  color: white;
}

.keyboard .oper, .keyboard #sign {
    background-color: Indigo;
}

calculator {
  border: 1px solid black;
}

#historyContent {
  border: 1px solid black;
  margin: 20px 0;
}

.historical {
  vertical-align: middle;
  border: 1px solid black;
}

#io {
  margin: 15px 0;
  display: grid;
  grid-gap: .4em;
}

row {
  display: block;
}

.keyboard {
  display: grid;
  grid-gap: 10px;
  grid-template-rows: repeat(5, 50px);
  justify-items: center;
}

.row {
    display: grid;
    grid-gap: 5px;
    grid-template-columns: repeat(4, 50px);
}

.wrapper {
  display: grid;
    grid-gap: 5px;
    grid-template-columns: 1fr 1fr 1fr;
}




            
          
!

JS

            
              /*
1. make mouse move
2. clear anno after calc
3. make anno italic
4. delete individual calcs
5. reduce repeatition & inconsistency 

1. leads to calcs?
2. clear history. No more calcs.
*/

let calc = "";
let counter = 1;
const opers = "+-**/";

function finalUpdate() {
  $("#formula").val(calc)
}

function evaluate() {
  if ($("#annotation").val() != "" | $("#formula").val() != "") {
    let anno = $("#annotation").val()
    let toBeInserted = ""
    if (anno != "") {
      toBeInserted = "<div class = 'historical' id =" + counter + " >" + counter + ". " + anno + ":" + "<br>" + calc + "=<br>" + eval(calc) + "</div>"
    }
    else {
      toBeInserted = "<div class = 'historical' id =" + counter + " >" + counter + ". "  + calc + "=<br>" + eval(calc) + "</div>"
    }
    $("#historyContent").prepend(toBeInserted)
    counter++
    calc = ""
    finalUpdate()
  }
}

function numUpdate(para) {
  calc += para
   finalUpdate()
}

function operUpdate(para) {
  if (calc.length !== 0) {
      const last = calc.slice(-1)
      if (opers.indexOf(last) === -1 ){
        calc += para
      }
    else if (opers.indexOf(last) >= 0 && calc.slice(-2) !== "**") {
         calc = calc.slice(0, -1) + para
      }
    else {
      calc = calc.slice(0, -2) + para
    }
      finalUpdate()
    }
}

function ceUpdate() {
  while (true) {
    if (opers.indexOf(calc.slice(-1)) >= 0) {
        break
        }
    calc = calc.slice(0, -1)
  }
  finalUpdate()
}

function acUpdate() {
    calc = ""
    finalUpdate()
}

function signUpdate() {
  calc = "-1*(" + calc + ")"
  finalUpdate()
}

$(document).ready(function () {
  $("#clearAnnotation").click(function () {
    $("#annotation").val("")
  })
  
  $("#clearFormula").click(function () {
    acUpdate()
  })
  
  $("#clearHistory").click(function () {
    document.getElementById("history").innerHTML = "History"
    let counter = 1
  })
  
  $(".num").click(function () {
    let para = this.innerHTML
   numUpdate(para)
  })
  
  $(".oper").click(function() {
    let para = this.innerHTML
    operUpdate(para)
  })
  
    $("#ac").click(acUpdate()
  )
  
  $("#ce").click(function() {
    ceUpdate()
  })
  
  $(".equal").click(function() {
    evaluate()
    $("#annotation").val("")
  })
  
  $("#sign").click(function() {
    signUpdate()
  })
  
  $( "#formula" ).change(function() {
    calc = $("#formula").val()
    evaluate()
  })
}
)
            
          
!
999px

Console