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

            
              <div id="top" class="text-center">
  <h4>
    CalculatorJs  
  </h4>
  
</div>
<div class="container" id="calculator">
  <div class="row justify-content-center">
    <div class="col-10 display d-flex-column">
      <div class="text-right justify-content-bottom" id="result">0</div>
      <div class="text-right" id="calculation"></div>
    </div>
    <div class="col-10">
      <div class="row">
        <button value="1" class="btn col-3" type="button">1</button>
        <button value="2" class="btn col-3" type="button">2</button>
        <button value="3" class="btn col-3" type="button">3</button>
        <button value="+" class="btn col-3" type="button">+</button>
      </div>
      <div class="row">
        <button value="4" class="btn col-3" type="button">4</button>
        <button value="5" class="btn col-3" type="button">5</button>
        <button value="6" class="btn col-3" type="button">6</button>
        <button value="-" class="btn col-3" type="button">-</button>
      </div>
      <div class="row">
        <button value="7" class="btn col-3" type="button">7</button>
        <button value="8" class="btn col-3" type="button">8</button>
        <button value="9" class="btn col-3" type="button">9</button>
        <button value="*" class="btn col-3" type="button">x</button>
      </div>
      <div class="row">
        <button  id="erase" value="erase" class="btn col-3" type="button">C</button>
        <button value="0" class="btn col-3" type="button">0</button>
        <button value="=" class="btn col-3" type="button">=</button>
        <button value="/" class="btn col-3" type="button">/</button>
      </div>
    </div>
  </div>
  
  <div class="row">
    <div class="col-10 text-center mx-auto mt-5">
      Designed and coded by <a href="https://github.com/misslild">misslild</a>
    </div>
  </div>
</div>
            
          
!

CSS

            
              body { 
  font-family: 'Poiret One', cursive;
    width: 100%;
  background: -webkit-linear-gradient(left, #22d686, #24d3d3, #22d686, #24d3d3);
  background: linear-gradient(to right, #22d686, #24d3d3, #22d686, #24d3d3);
  background-size: 600% 100%;
  -webkit-animation: HeroBG 20s ease infinite;
          animation: HeroBG 20s ease infinite;
}

@-webkit-keyframes HeroBG {
  0% {
    background-position: 0 0;
  }
  50% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

@keyframes HeroBG {
  0% {
    background-position: 0 0;
  }
  50% {
    background-position: 100% 0;
  }
  100% {
    background-position: 0 0;
  }
}

#top {
  margin-top: 5rem;
  color: white;
}

#calculator {
  width: 400px;
  margin: 4rem auto;
}

.display {
  background-color: black;
  height: 5.8rem;
  border-left: 1px solid grey;
  border-bottom: 1px solid grey;
}

#result {
  color: rgb(5, 252, 186);
  height: 3.5rem;
  align-self: flex-end;
  font-size: 2.5rem;
  padding-top: .7rem;
}

#calculation {
  color: darkgray;
  margin-top: .4rem;
}

button {
  padding: .5rem;
  color: rgb(5, 252, 186);
  background-color: rgb(27, 27, 28);
}

.btn {
  border-radius: 0;
  border-left: 1px solid grey;
  border-bottom: 1px solid grey;
  font-size: 2rem;
}

.btn:active {
  border: 1px solid white;
}

.btn:focus {
  box-shadow: none;
}

a {
  font-size: 1.3rem;
  color: white;
  font-weight: 700;
}

a:hover {
  color: grey;
  text-decoration: none;
}
            
          
!

JS

            
              // Calculator JS challenge for FreeCodeCamp

let value; // the mathematic value
let calculation = []; // what the user presses
let result; // the last result
let eraserCount; // checking if there is nothing to erase

// using calculator's buttons
$('button').on('click', function(e) {
  if (this.value === '=') {
    value = calculation.join(' ')
    result = eval(value)
    $('#result').html(result, value)
  }
  
  if (this.value !== 'erase' && this.value !== '=' ) {
    calculation.push(this.value)
  }
  
  if (this.value === 'erase') {
    calculation = []
    $('#calculation').html('')
    $('#result').html('0')
  }
  
  $('#calculation').html(calculation) 

})

// using keyboard
window.addEventListener('keydown', (e) => {
  if( e.key <= 9  || e.key === '*'   || e.key === '+'   || e.key === '-'   || e.key === '/') { 
    calculation.push(e.key)
    $('#calculation').html(calculation)    
  }
  
  $('#erase').on('click', (e) => {
    calculation = []
    $('#calculation').html(calculation) 
  })
  
  if (e.key === '=' || e.keyCode === 13) {
    e.preventDefault()
    value = calculation.join(' ')
    result = eval(value)
    $('#result').html(result, value)
  }
  
  if (e.keyCode === 8) {
    calculation.pop()
    if (calculation.length === 0) {
      $('#result').html(0)
    }
    
    $('#calculation').html(calculation) 
  }
})
            
          
!
999px

Console