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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

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

              
                <html>

<head>

</head>

<body>
  <div id="root"></div>
</body>

</html>
              
            
!

CSS

              
                .left-pane {
  float: left;
  width: 40%;
}
.right-pane {
  float: left;
  width: 60%;
}
.calculator {
  font-family: "Helvetica", sans-serif;
  background-color: pink;
}
.lodash {
  height: 30px;
  width: 60px;
  border: 1px solid #999;
}
.image-js, .decimal, .infinity, .e, .pi, .plusminus {
  height: 30px;
  width: 35px;
}
.image-js {
  margin-top: 1px;
}
.decimal, .infinity, .e, .pi, .plusminus {
  padding-top: 4px;
}
button.e,
button.pi {
  margin-top: 42px;
}
button {
  border-radius: 0px;
  border: 1px solid #999;
}
button:hover {
  background-color: green;
  color: white;
  box-shadow: 10px 10px 10px;
}
.clear {
  background-color: lightblue;
  color: black;
}
.num {
  height: 30px;
  width: 30px;
}
.equal-sign:focus {
  background-color: pink;
  color: black;
}
.equal-sign {
  height: 30px;
  width: 90px;
  background-color: darkblue;
  color: white;
}
input#expression {
  width: 200px;
  height: 35px;
  color: black;
  text-align: right;
  border-radius: 5px;
  margin-right: 15px;
  border: 2px solid lightblue;
  padding-right: 5px;
}
input#expression:focus {
  border: 2px solid green;
}
#result {
  color: blue;
}
error {
  border: 2px solid red;
}
div.border-999 {
  border: 2px solid #999;
  border-radius: 15px;
  width: 220px;
  background-color: lightgreen;
  padding: 10px 0px 10px 10px;
  margin-left: 25px;
  margin-top: 15px;
  box-shadow: 3px 7px 15px black;
  height: 235px;
}
hr {
  margin-left: 23px;
  border-bottom: 3px solid orange;
}
.sr-only {
  display: none;
}
.vertical-line {
  border-left: 6px solid rgb(13, 208, 25);
  height: 180px;
  position: absolute;
  left: 122px;
}

              
            
!

JS

              
                function Number(props){
  if(props.callMessage){
    props.callMessage();
  } else {
    console.log("Number " + props.children + " rendered");
  }
  
  return (
    <button className="num" onClick={props.onClick}>
      {props.children}
    </button>
  )
}

String.prototype.replaceAt=function(index, replacement) {
    return this.substr(0, index) + replacement+ this.substr(index + replacement.length);
}

class App extends React.Component {
  render(){
    return (
      <div>
        <h1 className="sr-only">Calculator</h1>
        <hr width="235" />
        <div className="border-999">
          <input id="expression" onKeyDown={this.handleKeySubmit}/>
          <br /><br />
          <div className="vertical-line" />
          <div className="left-pane">
            <div>
             <button className="image-js" onClick={this.handleBackspaceClick}><img src="https://cdn1.iconfinder.com/data/icons/Keyamoon-IcoMoon--limited/32/backspace.png" title="Backspace" height="14px"/></button>
              <button className="decimal" onClick={this.handleDecimalPointClick}>.</button>
            </div>
            <div>
              <button className="infinity" onClick={this.handleClickOnInfinity} title="Infinity">inf</button>
            </div>
            <br />
            <div>
              <button className="e" onClick={this.handleClickOnE}>e</button>
              <button className="pi" onClick={this.handleClickOnPI}>PI</button>
              <button className="plusminus" onClick={this.plusOrMinus}><sup>+</sup>/<sub>-</sub></button>
            </div>
          </div>
          <div className="right-pane">
            <div>
              <button className="lodash clear" onClick={this.clear}>Clear</button>
              <button className="lodash" onClick={this.handleClickOnMod}>mod</button>
            </div>
            <div>
              <button className="lodash" onClick=
                {
                  this.handleClickOn0S
                }
              >0</button>
              <Number onClick={this.handleClickOnOpening} callMessage={function(){
                  console.log("Bracket ( rendered");
                }}>(</Number>
              <Number onClick={this.handleClickOnClosing} callMessage={function(){
                  console.log("Bracket ) rendered");
                }}>)</Number>
            </div>
            <div>
              <Number onClick={this.handleClickOn1}>1</Number>
              <Number onClick={this.handleClickOn2}>2</Number>
              <Number onClick={this.handleClickOn3}>3</Number>
              <Number onClick={() => this.handleClickOnOperation("add")} 
                callMessage= {function(){
                  console.log("Sign + rendered");
                }}>+</Number>
            </div>
            <div>
              <Number onClick={this.handleClickOn4}>4</Number>
              <Number onClick={this.handleClickOn5}>5</Number>
              <Number onClick={this.handleClickOn6}>6</Number>
              <Number onClick={() => this.handleClickOnOperation("subtract")} 
                callMessage= {function(){
                  console.log("Sign - rendered");
                }}>-</Number>
            </div>
            <div>
              <Number onClick={this.handleClickOn7}>7</Number>
              <Number onClick={this.handleClickOn8}>8</Number>
              <Number onClick={this.handleClickOn9}>9</Number>
              <Number onClick={() => this.handleClickOnOperation("multiply")} 
                callMessage= {function(){
                  console.log("Sign * rendered");
                }}>&times;</Number>
            </div>
            <div>
              <button className="equal-sign" onClick={this.handleSubmit}>=</button>
              <Number onClick={() => this.handleClickOnOperation("divide")} 
                callMessage= {function(){
                  console.log("Sign / rendered");
                }}>&divide;</Number>
            </div>
          </div>
        </div>
      </div>
    )
  }
  handleBackspaceClick(){
    var exp = document.getElementById("expression");
    exp.value = exp.value.slice(0, -1);
  }
  handleDecimalPointClick(){
    var exp = document.getElementById("expression");
    exp.value += ".";
  }
  clear(){
    var exp = document.getElementById("expression");
    exp.value = "";
  }
  handleClickOnMod(){
    var exp = document.getElementById("expression");
    exp.value += "%";
  }
  handleClickOn0S(){
    var exp = document.getElementById("expression");
    if (exp.value !== ""){
      exp.value += "0";
    } else {
      return;
    }
  }
  handleClickOn1(){
    var exp = document.getElementById("expression");
    exp.value += "1";
  }
  handleClickOn2(){
    var exp = document.getElementById("expression");
    exp.value += "2";
  }
  handleClickOn3(){
    var exp = document.getElementById("expression");
    exp.value += "3";
  }
  handleClickOn4(){
    var exp = document.getElementById("expression");
    exp.value += "4";
  }
  handleClickOn5(){
    var exp = document.getElementById("expression");
    exp.value += "5";
  }
  handleClickOn6(){
    var exp = document.getElementById("expression");
    exp.value += "6";
  }
  handleClickOn7(){
    var exp = document.getElementById("expression");
    exp.value += "7";
  }
  handleClickOn8(){
    var exp = document.getElementById("expression");
    exp.value += "8";
  }
  handleClickOn9(){
    var exp = document.getElementById("expression");
    exp.value += "9";
  }
  handleClickOnE(){
    var exp = document.getElementById("expression");
    exp.value += Math.E;
  }
  handleClickOnPI(){
    var exp = document.getElementById("expression");
    exp.value += Math.PI;
  }
  handleClickOnOpening(){
    var exp = document.getElementById("expression");
    exp.value += "(";
  }
  handleClickOnClosing(){
    var exp = document.getElementById("expression");
    exp.value += ")";
  }
  handleClickOnOperation(operation){
    var exp = document.getElementById("expression");
    switch (operation){
      case "add":
        if (exp.value !== ""){
          exp.value += "+";
        };
        break;
      case "subtract":
        exp.value += "-";
        break;
      case "multiply":
        if (exp.value !== ""){
          exp.value += "*";
        };
        break;
      case "divide":
        if (exp.value !== ""){
          exp.value += "/";
        };
    }
  }
  handleClickOnInfinity(){
    var exp = document.getElementById("expression");
    exp.value += "Infinity";
  }
  handleSubmit(){
    var exp = document.getElementById("expression");
    if(exp.value !== ""){
      exp.value = eval(exp.value).toString();
    }
    else {
      alert("Please enter a expression.");
    }
  }
  handleKeySubmit(event){
    if(event.key === "Enter"){
      var exp = document.getElementById("expression");
      
      if(exp.value !== ""){
        exp.value = eval(exp.value).toString();
      } else {
        alert("Please enter expression");
      }
    } else {
      return;
    }
  }
}

ReactDOM.render(<App />, document.getElementById("root"));
              
            
!
999px

Console