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.

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="calc">
<div id="screen">
<h1 class="display">0</h1>
<h9 class="ghost"></h9>
</div>
<div id="buttons">
<div class="square ca">
  <p style="font-size:25px; padding-top:6px;">CA</p>
  </div>
<div class="square c">
  <p style="font-size:25px; padding-top:6px;">C</p>
  </div>
<div class="square divide">
  <p>÷</p>
  </div>
<div class="square times">
  <p>x</p>
  </div>
<div class="square seven">
  <p>7</p>
  </div>
<div class="square eight">
  <p>8</p>
  </div>
<div class="square nine">
  <p>9</p>
  </div>
<div class="square minus">
  <p>-</p>
  </div>
<div class="square four">
  <p>4</p>
  </div>
<div class="square five">
  <p>5</p>
  </div>
<div class="square six">
  <p>6</p>
  </div>
<div class="square plus">
  <p>+</p>
  </div>
<div class="square one">
  <p>1</p>
  </div>
<div class="square two">
  <p>2</p>
  </div>
<div class="square three">
  <p>3</p>
  </div>
<div class="square equals">
  <p>=</p>
  </div>
<div class="square zero" style="width:150px;">
  <p>0</p>
  </div>  
</div>
<div class="square dot">
  <p>.</p>
  </div>
</div>
<div class="history">
  <h3>History</h3>
  <br>  
</div>



              
            
!

CSS

              
                .calc {
  float:left;
  width:205px;
}
#buttons {
  width:200px;
  float:center;
}
.square {
  border-style:solid;
  border-color:black;
  border-width:1px 0px 0px 1px;
  font-size:30px;
  background-color:rgb(102, 96, 73);
  width:50px;
  height:50px;
  color:white;
  float:left;
}
.square:hover {
  background-color:black;
  opacity:0.8;
}
p {
  text-align:center;
}
.history {
  float:left;
  text-align:center;
  color:black;
  width:300px;
}
.history h3 {
  padding-top:20px;
  border-style:solid;
  border-color:rgb(102, 96, 73);
  border-width: 0px 0px 2px 0px;
  height:62px;
  text-align:center;
}
.historyP {
  background: linear-gradient(-90deg,orange, white 95%);
  margin-bottom:5px;  
  border-style:solid;
  border-color:rgb(102, 96, 73);
  border-width: 0px 5px 0px 0px
}
#screen {
  background-color:rgb(126, 175, 29);
  float:left;
  width:200px;
  border-style: solid;
  border-width: 5px;
  border-color:orange;
}



              
            
!

JS

              
                $(document).ready(function() {
  var lastNum = "0";
  var holder1 = "0";
  var action = "";
  var calculating = false;
  var justequaled = false;
  var ghost ="";
  function numTooLong(){
      holder1 = "0"
      $(".display").html("<p style='font-size:25px;'>Sorry bro, can't do that ;\(</p>");
      justequaled = true;
      calculating = false;
      action = ""; 
  };
  function numberPressed(numPressed){
    if (holder1.toString().length < 8) {
      
    calculating = false;
    switch(numPressed){
      case "1":
        if (holder1 === "0" || justequaled) {
         holder1 = "1";
        } else {
      holder1 = holder1.concat("1");
          }
        break;
      case "2":
         if (holder1 === "0" || justequaled) {
         holder1 = "2";
        } else {
      holder1 = holder1.concat("2");
          }
        break;
      case "3":
         if (holder1 === "0" || justequaled) {
         holder1 = "3";
        } else {
      holder1 = holder1.concat("3");
          }
        break;
      case "4":
         if (holder1 === "0" || justequaled) {
         holder1 = "4";
        } else {
      holder1 = holder1.concat("4");
          }
        break;
      case "5":
         if (holder1 === "0" || justequaled) {
         holder1 = "5";
        } else {
      holder1 = holder1.concat("5");
          }
        break;
      case "7":
         if (holder1 === "0" || justequaled) {
         holder1 = "7";
        } else {
      holder1 = holder1.concat("7");
          }
        break;
      case "8":
         if (holder1 === "0" || justequaled) {
         holder1 = "8";
        } else {
      holder1 = holder1.concat("8");
          }
        break;
      case "9":
         if (holder1 === "0" || justequaled) {
         holder1 = "9";        
        } else {
         holder1 = holder1.concat("9");
          }
        break;
    }  
    justequaled = false;
    $(".display").html(holder1);
    } else {
      numTooLong();
    }
  }
  function CalculateSome() {    
    switch (action) {
        case "plus":
          holder1 = parseFloat(lastNum) + parseFloat(holder1);
          break;
        case "minus":
          holder1 = parseFloat(lastNum) - parseFloat(holder1);
          break;
        case "times":
          holder1 = parseFloat(lastNum) * parseFloat(holder1);
          break;
        case "divide":
          holder1 = parseFloat(lastNum) / parseFloat(holder1);
          break;
      }
       holder1 = +(Math.round(holder1 + "e+7")  + "e-7");
       if (holder1.toString().length > 8) {
           numTooLong();
       } else {
       $(".display").html(holder1); }
} 
  $(".equals").on("click", function() {
    if (!calculating && action !== "") {
        ghost = ghost + holder1;
        CalculateSome();
        if (action === "") {
          $(".history").append("<p class='historyP'>"+ghost.concat(" = "+ "Number too long")+"<p>");
        } else { 
          $(".history").append("<p class='historyP'>"+ghost.concat(" = "+holder1)+"<p>"); 
        }
          ghost= "";
        $(".ghost").html("");
          action = "";
          justequaled = true;
    }
  });
  $(".plus").on("click", function() {
    if (!calculating && !justequaled) {
      ghost = ghost.concat(holder1 + " + ");  
      $(".ghost").html(ghost);
      CalculateSome();
      calculating = true;
      lastNum = holder1;
      holder1 = "0";
      action = "plus";
    }
  });
  $(".minus").on("click", function() {
    if (!calculating && !justequaled) {
      ghost = ghost.concat(holder1 + " - "); 
      $(".ghost").html(ghost);
      CalculateSome();
      calculating = true;
      lastNum = holder1;
      holder1 = "0";
      action = "minus";
    }
  });
  $(".times").on("click", function() {
    if (!calculating && !justequaled) {
      ghost = ghost.concat(holder1 + " x ");  
      $(".ghost").html(ghost);
      CalculateSome();
      calculating = true;
      lastNum = holder1;
      holder1 = "0";
      action = "times";
    }
  });
  $(".divide").on("click", function() {
    if (!calculating && !justequaled) { 
      ghost = ghost.concat(holder1 + " ÷ ");  
      $(".ghost").html(ghost);
      CalculateSome();
      calculating = true;
      lastNum = holder1;
      holder1 = "0";
      action = "divide";
    }
  });
  $(".zero").on("click", function() {
    calculating = false;
    if (holder1 !== "0" && !justequaled) {
      holder1 = holder1.concat("0");
    }
    else if (justequaled) {
       holder1 = "0";
       justequaled = false;      
     }
    $(".display").html(holder1);
  });
  $(".one").on("click", function() {
    numberPressed("1");
  });
  $(".two").on("click", function() {
    numberPressed("2");
  });
  $(".three").on("click", function() {
    numberPressed("3");
  });
  $(".four").on("click", function() {
    numberPressed("4");
  });
  $(".five").on("click", function() {
    numberPressed("5");
  });
  $(".six").on("click", function() {
    numberPressed("6");
  });
  $(".seven").on("click", function() {
    numberPressed("7");
  });
  $(".eight").on("click", function() {
    numberPressed("8");
  });
  $(".nine").on("click", function() {
    numberPressed("9");
  });
  $(".ca").on("click", function() {
    calculating = false;
    lastNum = "";
    holder1 = "0";
    action = "";
    ghost ="";
    $(".display").html(holder1);
    $(".ghost").html(ghost);
  });
  $(".c").on("click",function(){
    holder1="0";
    $(".display").html(holder1);
  });
  $(".dot").on("click", function() {
    calculating = false;
    holder1 = holder1.concat(".");
    justequaled = false;      
    $(".display").html(holder1);
  });
});

              
            
!
999px

Console