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.

Quick-add: + add another resource

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.

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.

            
              <p>
  <input type="number" value="12" class="number-input number-input--a" />
  <select class="operator-select">
    <option value="add">+</option>
    <option value="subtract">-</option>
    <option value="multiply">×</option>
    <option value="divide">÷</option>
  </select>
  <input type="number" value="4" class="number-input number-input--b" />
</p>

<p class="result"></p>
            
          
!
            
              body {
  background: #EEE;
  font-family: sans-serif;
}

input, select {
  font-size: 20px;
}

input {
  width: 100px;
  text-align: right;
}

.result {
  padding: 10px;
  font-size: 36px;
  background: #19F;
  color: white;
  text-align: right;
  max-width: 240px;
  border-radius: 5px;
  font-weight: bold;
  overflow: hidden;
  text-overflow: ellipsis;
}
            
          
!
            
              var $numberInputs = $('.number-input');
var $inputA = $('.number-input--a');
var $inputB = $('.number-input--b');
var $operatorSelect = $('.operator-select');
var $result = $('.result');

var operations = {
  add: function( a, b ) {
    return a + b;
  },
  subtract: function( a, b ) {
    return a - b;
  },
  multiply: function( a, b ) {
    return a * b;
  },
  divide: function( a, b ) {
    return a / b;
  },
};

function calculate() {
  var a = parseInt( $inputA.val(), 10 );
  var b = parseInt( $inputB.val(), 10 );
  var operator = $operatorSelect.val();
  var operation = operations[ operator ];
  var resultNumber = operation( a, b );
  $result.text( resultNumber );
}

// calculate initial value
calculate();

// calculate on change events
$numberInputs.on( 'input', calculate );
$operatorSelect.on( 'change', calculate );
            
          
!
999px
Loading ..................

Console