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 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

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

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

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

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.

            
              .calculator
  p#title FreeCodeCamp
  p#tagline electronic calculator
  input(type='text' disabled)#answer
  .row
    button.ctrl AC
    button.ctrl CE
    button %
    button ÷
  .row
    button 7
    button 8
    button 9
    button x
  .row
    button 4
    button 5
    button 6
    button -
  .row
    button 1
    button 2
    button 3
    button.tall +
  .row
    button 0
    button .
    button =
            
          
!
            
              @import "bourbon";

// Fonts
@import url(https://fonts.googleapis.com/css?family=Pacifico|Open+Sans|Montserrat);

// Colors
$darkTan: #9B8F89;
$tan: #F3EEE7;
$grey: #969194;
$green: #C7C7B0;
$darkGrey: #4B4657;
$red: #CC4E5F;

body, html {
  width: 100%;
  background-color: $darkTan;
}

.calculator {
  width: 250px;
  height: 335px;
  background-color: $tan;
  margin: 0 auto;
  
  // Curved edges
  border-top-left-radius: 80%20px;
  border-top-right-radius: 80%20px;
  border-bottom-left-radius: 80%20px;
  border-bottom-right-radius: 80%20px;
  
  // Left and right shadows
  box-shadow: inset 5px 0 10px -5px darken($grey, 20),
              inset -5px 0 10px -5px darken($grey, 20),
              inset 0px -5px 10px -2px darken($grey, 20),
                    0 0 1px 2px darken($grey, 20),
                    0 10px 20px 0 darken($grey, 30);
  
  // Title
  text-align: center;
  p#title {
    padding-top: 10px;
    margin-bottom: -10px;
    color: darken($grey, 10);
    font-family: 'Pacifico';
  }
  p#tagline {
    text-transform: uppercase;
    color: $grey;
    font-family: 'Open Sans';
    font-size: .7em;
  }
  
  // Numbers input box
  input[type='text'] {
    background-color: $green;
    border: 1px solid darken($green, 10);
    line-height: 40px;
    width: 80%;
    font-size: 2em;
    direction: rtl;
    font-family: 'Montserrat';
    padding-right: 10px;
    margin-bottom: 20px;
    border-radius: 5px;
    box-shadow: inset 0px -2px 10px darken($green, 10);
    &:focus {
      outline: none;
    }
  }
  
  // Buttons
  .row {
    display: block;
    button {
      width: 40px;
      height: 30px;
      border: 1px solid $darkGrey;
      border-top: 2px solid lighten($darkGrey, 20);
      @include background-image(linear-gradient(to bottom, $darkGrey, darken($darkGrey, 10)));
      color: white;
      font-size: 1.1em;
      border-radius: 20%;
      border-top-left-radius: 80%10px;
      border-top-right-radius: 80%10px;
      border-bottom-left-radius: 100%10px;
      border-bottom-right-radius: 100%10px;
      margin-left: 5px;
      margin-right: 5px;
      margin-bottom: 8px;
      box-shadow: inset 0 1px 4px lighten($darkGrey, 20),
                  inset 0 -4px 20px darken($darkGrey, 10),
                        0 3px 1px 0 darken($darkGrey, 10);
      &:focus {
        outline: 0;
      }
      
      &:active {
        @include background-image(linear-gradient(to top, $darkGrey, darken($darkGrey, 10)));
      }

    }
    .ctrl {
      border: 1px solid $red;
      border-top: 2px solid lighten($red, 20);
      @include background-image(linear-gradient(to bottom, $red, darken($red, 10)));
      box-shadow: inset 0 1px 4px lighten($red, 20),
                  inset 0 -4px 20px darken($red, 10);
      &:active {
        @include background-image(linear-gradient(to top, $red, darken($red, 10)));
      }
    }
    .tall {
      height: 65px;
      float: right;
      margin-right: 24px;
      margin-left:  -8px;
    }
  }
}
            
          
!
            
              var entries = [];
var total = 0;

var temp = '';
$("button").on('click', function() {
 	var val = $(this).text();

  // Got a number, add to temp
  if (!isNaN(val) || val === '.') {
    temp += val;
    $("#answer").val(temp.substring(0,10));
    
  // Got some symbol other than equals, add temp to our entries
  // then add our current symbol and clear temp
  } else if (val === 'AC') {
    entries = [];
    temp = '';
    total = 0;
    $("#answer").val('')

  // Clear last entry
  } else if (val === 'CE') {
    temp = '';
    $("#answer").val('')
    
  // Change multiply symbol to work with eval
  } else if (val === 'x') {
    entries.push(temp);
    entries.push('*');
    temp = '';
    
  // Change divide symbol to work with eval
  } else if (val === '÷') {
    entries.push(temp);
    entries.push('/');
    temp = '';

  // Got the equals sign, perform calculation
  } else if (val === '=') {
  	entries.push(temp);

    var nt = Number(entries[0]);
    for (var i = 1; i < entries.length; i++) {
      var nextNum = Number(entries[i+1])
      var symbol = entries[i];
      
      if (symbol === '+') { nt += nextNum; } 
      else if (symbol === '-') { nt -= nextNum; } 
      else if (symbol === '*') { nt *= nextNum; } 
      else if (symbol === '/') { nt /= nextNum; }
      
      i++;
    }
    
    // Swap the '-' symbol so text input handles it correctly
    if (nt < 0) {
      nt = Math.abs(nt) + '-';
    }
    
    $("#answer").val(nt);
		entries = [];
    temp = '';
    
  // Push number
  } else {
    entries.push(temp);
    entries.push(val);
    temp = '';
  }
});
            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console