cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - Activehtmlicon-personicon-teamoctocatspinnerstartv

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.

            
              <select class="operand1">
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
</select>
<select class="operator">
	<option value="+">+</option>
	<option value="-">-</option>
	<option value="*">*</option>
	<option value="/">/</option>
</select>
<select class="operand2">
	<option value="1">1</option>
	<option value="2">2</option>
	<option value="3">3</option>
</select>
<input type="text" class="input">
            
          
!
            
              select{
    display: inline-block;
    padding: 14px 10px;
    border: 1px solid #a7a7aa;
    border-radius: 3px;
    background-color: #cccccc;
    text-decoration: none;
    text-align: center;
    font-size: 14px;
    line-height: 1;
    background-color: #e1e1e1;
    font-size:16px;
    filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#fff9f9f9', endColorstr='#ffe1e1e1', GradientType=0);
    background-image: -moz-linear-gradient(top, #f9f9f9, #e1e1e1);
    background-image: -ms-linear-gradient(top, #f9f9f9, #e1e1e1);
    background-image: -o-linear-gradient(top, #f9f9f9, #e1e1e1);
    background-image: -webkit-gradient(linear, center top, center bottom, from(#f9f9f9), to(#e1e1e1));
    background-image: -webkit-linear-gradient(top, #f9f9f9, #e1e1e1);
    background-image: linear-gradient(top, #f9f9f9, #e1e1e1);
    color: #333333;
    padding-top: 17px;
    padding-bottom: 15px;
    text-align: left;
}
input{
    font-size: 15px;
    padding-top: 5px;
    padding-bottom: 4px;
    border: 1px solid #a7a7aa;
    border-radius: 3px;
    color: #333;
    line-height: 1;
    box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1) inset;
}
            
          
!
            
              $(function(){
	//operand1に入力された値のマッピング
	var stream1 = $(".operand1")
	.asEventStream("input")
	.map(function(e){
		return {operand1:parseInt($(e.target).val())};
	});
	//.operatorに入力された値のマッピング
	var stream2 = $(".operator")
	.asEventStream("input")
	.map(function(e){
		return {operator:$(e.target).val()};
	});
	//.operand2に入力された値のマッピング
	var stream3 = $(".operand2")
	.asEventStream("input")
	.map(function(e){
		return {operand2:parseInt($(e.target).val())};
	});
	//それらのストリーミングのマージ
	var stream4 = stream1.merge(stream2).merge(stream3);
	//オブジェクトの初期値
	var initialValue = {operand1:1,operator:"+",operand2:1};
	//オブジェクトを拡張するための関数
	var extendObj = function(curr,v){
		return $.extend(curr,v);
	}
	//オブジェクトから四則演算を行うための関数
	var calcFromObj = function(curr,v){
		if(v.operator == "+"){
			return v.operand1 + v.operand2;
		}else if(v.operator == "-"){
			return v.operand1 - v.operand2;
		}else if(v.operator == "*"){
			return v.operand1 * v.operand2;
		}else{
			return v.operand1 / v.operand2;
		}
	}
	//マージされたストリーミングから流れてきたオブジェクトで初期値を拡張
	var stream5 = stream4.scan(initialValue,extendObj);
	//拡張されたオブジェクトから四則演算の結果値を取得
	var stream6 = stream5.scan(2,calcFromObj);
	//取得した結果値を.inputにアサイン
	stream6.assign($(".input"),"val");
});
            
          
!
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