cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

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.

            
              <div id="main">
  <div id="screen">
    <p id="display"> </p>
  </div>
  <div id="buttons">
    <div class="row">
      <button id="all_clear">AC</button>
      <button id="clear_screen">CE</button>
      <button id="percent">%</button>
      <button class= "op" id="divide">/</button>
    </div>
    <div class="row">
      <button class= "num">7</button>
      <button class= "num">8</button>
      <button class= "num">9</button>
      <button class= "op" id="multi">*</button>
    </div>
    <div class="row">
    <button class="num">4</button>
    <button class="num">5</button>
    <button class="num">6</button>
    <button class= "op" id="subtract">-</button>
    </div>
    <div class="row row-bottom">
    <button class="num">1</button>
    <button class="num">2</button>
    <button class="num">3</button>
    </div>
     <button class= "op" id="add">+</button>
    <div class="row row-bottom">
    <button class="num">0</button>
    <button id="decimal">.</button>
    <button id="equal">=</button>
    </div>
  </div>
</div>
            
          
!
            
              $button_color: darken(#778899, 20%);
$background_color: #778899;
$screen_color: #0f0f0a;
$screen_text: #66e0ff; 
$button_text: #568e90; 

@mixin num_button {
  width:  40px;
  height: 40px;
  margin: 2px;
  background: $button_color;
  border-radius: 15%;
  border-color: darken($button_color, 5%);
  color: $button_text;
}


@mixin centerer {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
}

@mixin centerer-sides {
  position: absolute;
  left: 50%;
  transform: translate(-50%);
  margin-top: 20px;
  text-align: center;
}

body {
  background-color: darken($button_color, 25%);
}

#main {
  @include centerer;
  height: 400px;
  width: 240px;
  border: darken($button_color, 5%) 3px solid;
  background: #778899;
  border-radius: 5%;
}

#screen {
  @include centerer-sides;
  height: 25%;
  width: 80%;
  background: $screen_color;
  color: $screen_text;
  border-radius: 5%;
}

#buttons {
  @include centerer-sides;
  margin-top: 150px;
  width: 192px;
  height: 220px;
}

.row {
    button {
      @include num_button;
    }
    &.row-bottom {
      float:left;
    }
  }

#add {
    background: $button_color;
    color: $button_text;
    border-color: darken($button_color, 5%);
  float:right;
    border-radius: 15%;
    margin: 3px;
    width: 40px;
    height: 84px;
}

#display {
  padding: 5px;
  font-size: 20px;
  }
            
          
!
            
              //store entry until = button is pressed
//on click add the proper number or fuction
//convert buildString to Number before using operators 
var buildString = "";
var runningTotal = ""; 
//running total will hold the whole nummber until presssing equal

//Number Buttons
$(".num").click(function(e){
  var num = e.target.innerHTML;
  buildString += num;
 
  runningTotal += num; 
  if(buildString.length <= 16){
  console.log("the total is " + runningTotal);
  $("#display").html(buildString);
  } else {
    $("#display").html("number is too long");
  }
});

//Clear Buttons

$("#all_clear").click(function(){
  buildString = "";
   runningTotal = "";
  $("#display").html(buildString);
  console.log("all clear")
});

$("#clear_screen").click(function(){
  $("#display").html("");
  buildString = "";
  console.log("screen cleared");
  console.log(buildString);
});

//Ops 

$(".op").click(function(e){
  var op = e.target.innerHTML;
  buildString = op;
  runningTotal += op; 
    if(buildString.length <= 16){
      $("#display").html(buildString);
    }else {
        $("#display").html("number is too long");
    }
});


$("#percent").click(function(){
  if(buildString.indexOf("%") == -1) {
    buildString += "%";
    runningTotal += "/100"; 
  } else {
    console.log("can't add percent sign")
  }
    if(buildString.length <= 10){
    $("#display").html(buildString);
  } else {
        $("#display").html("number is too long");
    }
});


$("#decimal").click(function(){
  if(runningTotal.indexOf(".") == -1 && runningTotal.indexOf("%") == -1)  {
    buildString += ".";
    runningTotal += "."; 
  } else {
    console.log("can't add decimal")
  }
    if(buildString.length <= 16){
    $("#display").html(buildString);
  } else {
        $("#display").html("number is too long");
    }
});

$("#equal").click(function(){
  //parseInt or use mathEval
  try {
   var finalVal = eval(runningTotal);
   $("#display").html(finalVal);
  } catch(err) {
     $("#display").html("Error");
    }
    //reset
    buildString = "";
    runningTotal = "";
});


            
          
!
999px
Close

Asset uploading is a PRO feature.

As a PRO member, you can drag-and-drop upload files here to use as resources. Images, Libraries, JSON data... anything you want. You can even edit them anytime, like any other code on CodePen.

Go PRO

Loading ..................

Console