Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                a<div id="app"></div>
              
            
!

CSS

              
                @font-face
  font-family: "LCD"
  src: url("//db.onlinewebfonts.com/t/233131eb5b5e4a930cbdfb07008a09e1.eot")
  src: url("//db.onlinewebfonts.com/t/233131eb5b5e4a930cbdfb07008a09e1.eot?#iefix") format("embedded-opentype"), url("//db.onlinewebfonts.com/t/233131eb5b5e4a930cbdfb07008a09e1.woff2") format("woff2"), url("//db.onlinewebfonts.com/t/233131eb5b5e4a930cbdfb07008a09e1.woff") format("woff"), url("//db.onlinewebfonts.com/t/233131eb5b5e4a930cbdfb07008a09e1.ttf") format("truetype"), url("//db.onlinewebfonts.com/t/233131eb5b5e4a930cbdfb07008a09e1.svg#LCD") format("svg")

body
  background-color: #2E0A3C
  background-image: url("https://d2v9y0dukr6mq2.cloudfront.net/video/thumbnail/ro7gaTGVVjrn6n787/videoblocks-80s-retro-background-4k_bv-jnafone_thumbnail-full01.png")
  background-position: center center
  background-attachment: fixed
  background-size: cover
  background-repeat: no-repeat
  padding-top: 100px

.container
  width: 400px
  margin: 0 auto
  background: #E4D8B4
  border-radius: 8px
  border-bottom: 15px solid rgba(0,0,0,0.3)
  padding: 30px
  text-align: center
  box-shadow: inset 0 1px 5px 5px rgba(0,0,0,0.2)

#display
  display: block
  height: 100px
  border: 15px inset #aaa
  background: #333
  margin-bottom: 25px
  color: rgba(255,255,255,0.4)
  letter-spacing: 1px
  text-align: right
  padding: 0 30px
  line-height: 2
  font-size: 3em
  font-family: 'LCD'

button
  cursor: pointer
  background: linear-gradient(#83B799, #729e84)
  border-top-left-radius: 4px
  border-top-right-radius: 4px
  border-bottom-left-radius: 2px
  border-bottom-right-radius: 2px
  border-right: 1px solid #4d6b5a
  border-left: 1px solid #4d6b5a
  border-bottom: 9px solid #4d6b5a
  border-top: 1px solid #4d6b5a
  padding: 18px 30px
  color: #fff
  font-weight: bold
  position: relative
  box-shadow: 0 2px 1px 2px rgba(0,0,0,0.6), inset 0 0 3px 4px rgba(0,0,0,.075)
  font-size: 1.2em
  display: inline-block

button:active
  background: linear-gradient(#729e84, #83B799)
  border-top: 1px solid #4d6b5a
  border-bottom: 3px solid #4d6b5a
  margin-top: 3px
  box-shadow: 0 1px 1px 2px rgba(0,0,0,0.6), inset 0 0 3px 4px rgba(0,0,0,.05)

button.red:active
  background: linear-gradient(#B35550, #E86F68)
  border-top: 1px solid #B35550
  border-bottom: 3px solid #B35550

button.gray:active 
  background: linear-gradient(#7F7F7F, #999)
  border-top: 1px solid #777
  border-bottom: 3px solid #666

button:focus
  outline: none

.red
  background: linear-gradient(#994945, #E86F68)
  color: #fff
  border-color: #994945

.gray
  background: linear-gradient(#999, #7F7F7F)
  color: #333
  border-color: #666

#calculator
  margin: 0 auto
  display: grid
  grid-template-columns: repeat(4, 1fr)
  grid-template-rows: repeat(5, minmax(80px, auto))
  grid-gap: 12px 15px

  button:active
    height: calc(100% - 2px)

  .span-h
    grid-column: span 2
   
  .span-v
    grid-row: span 2
   
   
.control
  text-align: right

.brand
  font-family: "Impact", sans-serif
  float: left
  font-size: 1.8em
  line-height: 1
  text-shadow: -1px -1px 0px rgba(255, 255, 255, 0.3), 1px 1px 0px rgba(0, 0, 0, 0.8)
  color: #222
  opacity: 0.7

.switch
  position: relative
  display: inline-block
  width: 60px
  height: 34px
  margin-bottom: 20px

  input
    opacity: 0
    width: 0
    height: 0

.slider
  position: absolute
  cursor: pointer
  top: 0
  left: 0
  right: 0
  bottom: 0
  background-color: #ccc
  -webkit-transition: .4s
  transition: .4s
  &:before
    position: absolute
    content: ""
    height: 26px
    width: 26px
    left: 4px
    bottom: 4px
    background-color: white
    -webkit-transition: .4s
    transition: .4s

input
  &:checked + .slider
    background-color: #2196F3
  &:focus + .slider
    box-shadow: 0 0 1px #2196F3
  &:checked + .slider:before
    -webkit-transform: translateX(26px)
    -ms-transform: translateX(26px)
    transform: translateX(26px)
              
            
!

JS

              
                console.clear()

class Calculator extends React.Component {
   constructor(props) {
      super(props)
      this.state = {
         input: [],
         tempInput: [],
         output: ["0"],
         hasComma: false,
         operator: null,
         negativeOperator: false
      }
      this.getButtonValue = this.getButtonValue.bind(this)
      this.setOperator = this.setOperator.bind(this)
      this.equate = this.equate.bind(this)
   }

   equate() {
      const { input, output, operator, tempInput } = this.state

      this.setState({
         input: [eval(input.join("") + operator + tempInput.join("")).toString()],
         tempInput: [],
         operator: null,
         output: [eval(input.join("") + operator + tempInput.join("")).toString()]
      }, () => console.log("state", this.state))
   }
   
   // 3 + 5 * 6 - 2 / 4

   clear() {
      // Set state back to initial state
      this.setState({
         input: [],
         tempInput: [],
         output: ["0"],
         hasComma: false,
         operator: null,
         negativeOperator: false
      })
   }

   setOperator(event) {
      
      const { tempInput, input, output, operator, negativeOperator } = this.state
      
      if (!this.state.input.length && event.target.textContent == "-") {
         // If input is empty, and operator is "-"
         this.setState({
            input: [...input, event.target.textContent],
            output: [...input, event.target.textContent],
            negativeOperator: true
         }, () => console.log("state", this.state))
      } else if (event.target.textContent === "-" && !operator && !negativeOperator) {
         // If an operation is started, init a negative number
         this.setState({
            tempInput: [...tempInput, event.target.textContent],
            output: [...tempInput, event.target.textContent],
            negativeOperator: true
         }, () => console.log("state minush", this.state))
      } else if (event.target.textContent !== "-") {
         // If the operator is not minus, set the operator as usual
         this.setState({
            // set x value to *, else set the others as normal
            operator: event.target.textContent === "x" ? "*" : event.target.textContent
         }, () => console.log("state", this.state))
      } else if (negativeOperator && event.target.textContent === "-") {
         this.setState({
            operator: event.target.textContent
         }, () => console.log("state", this.state))
      } else if (!negativeOperator && operator !== '-' && event.target.textContent === "-") {
         this.setState({
            operator: event.target.textContent
         }, () => console.log("state", this.state))
      }
   }
   
   // Max number of rounded decimals = 8?
   // Max number of numbers when inputting  = 15

   getButtonValue(event) {

      const { input, output, tempInput, hasComma, operator } = this.state

       switch (event.target.textContent) {
          case ".":
             if (!this.state.input.length) {
                // If input is empty, add zero before comma 
                this.setState({
                   input: ["0", event.target.textContent],
                   output: ["0", event.target.textContent],
                   hasComma: true
                }, () => console.log("state", this.state))
             } else if (this.state.input[0] === "0" && !hasComma && !operator) {
                // If first number is zero, add comma
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent],
                   hasComma: true
                }, () => console.log("state", this.state))
             } else if (!hasComma && !operator) {
                // If it's a whole number and doesn't have comma or operator, add comma
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent],
                   hasComma: true
                }, () => console.log("state", this.state))       
             } else if (operator && !this.state.tempInput.length) {
                // If an operation is selected, add zero before comma
                this.setState({
                   tempInput: ["0", event.target.textContent],
                   output: ["0", event.target.textContent],
                   hasComma: true
                }, () => console.log("state", this.state))             
             } else if (operator && parseInt(this.state.tempInput[0]) > 0) {
                // If an operation is selected, add zero before comma
                this.setState({
                   tempInput: [...tempInput, event.target.textContent],
                   output: [...tempInput, event.target.textContent],
                   hasComma: true
                }, () => console.log("state", this.state))             
             } else if (this.state.tempInput[0] === "0" && operator) {
                // If an operation is selected, add zero before comma
                this.setState({
                   tempInput: ["0", event.target.textContent],
                   output: ["0", event.target.textContent],
                   hasComma: true
                }, () => console.log("state", this.state))        
             }
             break
          case "0":
             if (!this.state.input.length && !hasComma) {
                // If input is empty and there is no comma
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent]
                }, () => console.log("state", this.state))
               
             } else if (this.state.input[0] == "0" && this.state.input[1] == ".") {
                // If input is "0.", continue adding numbers
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent]
                }, () => console.log("state", this.state))
                
             } else if (this.state.input.length && hasComma && !operator) {
                // if there is some input and it's a decimal number
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent]
                }, () => console.log("state", this.state))
             } else if (this.state.input.length && hasComma && operator) {
                // if there is some input and it's a decimal number and a selected operator
                this.setState({
                   tempInput: [...tempInput, event.target.textContent],
                   output: [...tempInput, event.target.textContent],
                }, () => console.log("state", this.state))
             } else if (parseInt(this.state.input[0]) > 0 && !hasComma) {
                // if the input is a number, value is greater than 0, and is a whole number
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent]
                }, () => console.log("state", this.state)) 
             }
             break
          case "1":
          case "2":
          case "3":
          case "4":
          case "5":
          case "6":
          case "7":
          case "8":
          case "9":
             if (this.state.input[0] == "0" && !hasComma) {
                this.setState({
                   input: [event.target.textContent],
                   output: [event.target.textContent]
                }, () => console.log("state", this.state))
             } else if (operator) {
                this.setState({
                   tempInput: [...tempInput, event.target.textContent],
                   output: [...tempInput, event.target.textContent]
                }, () => console.log("state", this.state))
             } else {
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent]
                }, () => console.log("statez", this.state))      
             }
             break
          default:
             this.setState({
                output: "ERROR"
             })
             break
       }
   }
   
   render() {
      const { output } = this.state
      return (
         <div className='container'>
            <div id="display">
               { output }
            </div>
            <div className="control">
               <div className="brand">
                  калькулятор
               </div>
               <label className="switch">
                 <input type="checkbox" />
                 <span className="slider"></span>
               </label>
            </div>
            <div id="calculator">
               <button id="clear" className="span-h red" onClick={() => this.clear()}>AC</button>
               <button id="divide" onClick={this.setOperator} className="gray">/</button>
               <button id="multiply" onClick={this.setOperator} className="gray">x</button>
               <button id="seven" onClick={this.getButtonValue}>7</button>
               <button id="eight" onClick={this.getButtonValue}>8</button>
               <button id="nine" onClick={this.getButtonValue}>9</button>
               <button id="subtract" onClick={this.setOperator} className="gray">-</button>
               <button id="four" onClick={this.getButtonValue}>4</button>
               <button id="five" onClick={this.getButtonValue}>5</button>
               <button id="six" onClick={this.getButtonValue}>6</button>
               <button id="add" onClick={this.setOperator} className="gray">+</button>
               <button id="one" onClick={this.getButtonValue}>1</button>
               <button id="two" onClick={this.getButtonValue}>2</button>
               <button id="three" onClick={this.getButtonValue}>3</button>
               <button id="equals" onClick={this.equate} className="span-v gray">=</button>
               <button id="zero" onClick={this.getButtonValue} className="span-h">0</button>
               <button id="decimal" onClick={this.getButtonValue} className="gray">.</button>
            </div>
         </div>

      )
   }
}

ReactDOM.render(
   <Calculator />,
   document.getElementById('app')
)

/*
   EXAMPLE: 3 + 5 x 6 - 2 / 4 =
   Immediate Execution Logic: 11.5
   Formula/Expression Logic: 32.5
*/
VanillaTilt.init(document.querySelector(".container"), {
   glare: true,
   "max-glare": 0.2
});

/*

3.23 + 33.2

input = ["3", "3"]


this.state = {
   initialInput: [],
   tempInput: [],
   output: ["0"]
}

this.state = {
   initialInput: ["2", ".", "3"],
   tempInput: [],
   output: initalInput, ...
}

ouput = ["3", "3"]

pressing = should update both initial and ouput to the same
clear temp input

*/
 
 
 
/*

class Calculator extends React.Component {
   constructor(props) {
      super(props)
      this.state = {
         input: [],
         tempInput: [],
         output: ["0"],
         hasComma: false,
         operator: null
      }
      this.getButtonValue = this.getButtonValue.bind(this)
      this.setOperator = this.setOperator.bind(this)
      this.equate = this.equate.bind(this)
   }

   equate() {
      const { input, output, operator, tempInput } = this.state

      this.setState({
         input: [eval(input.join("") + operator + tempInput.join("")).toString()],
         tempInput: [],
         operator: null,
         output: [eval(input.join("") + operator + tempInput.join("")).toString()]
      }, () => console.log("state", this.state))
   }
   
   // 3 + 5 * 6 - 2 / 4
   
   clear() {
      // Set state back to initial state
      this.setState({
         input: [],
         tempInput: [],
         output: ["0"],
         hasComma: false,
         operator: null
      })
   }

   setOperator(event) {
      
      const { operator } = this.state
      
      if ( operator ) {
         // If there is an operator, run equation
         this.equate()
      }
      this.setState({
         // set x value to *, else set the others as normal
         operator: event.target.textContent === "x" ? "*" : event.target.textContent
      }, () =>  console.log("state", this.state))
   }
   
   // Max number of rounded decimals = 8?
   // Max number of numbers when inputting  = 15

   getButtonValue(event) {

      const { input, output, tempInput, hasComma, operator } = this.state

       switch (event.target.textContent) {
          case ".":
             if (!this.state.input.length) {
                // If input is empty, add zero before comma 
                this.setState({
                   input: ["0", event.target.textContent],
                   output: ["0", event.target.textContent],
                   hasComma: true
                }, () => console.log("state", this.state))
             } else if (this.state.input[0] === "0" && !hasComma && !operator) {
                // If first number is zero, add comma
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent],
                   hasComma: true
                }, () => console.log("state", this.state))
             } else if (!hasComma && !operator) {
                // If it's a whole number and doesn't have comma or operator, add comma
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent],
                   hasComma: true
                }, () => console.log("state", this.state))       
             } else if (operator && !this.state.tempInput.length) {
                // If an operation is selected, add zero before comma
                this.setState({
                   tempInput: ["0", event.target.textContent],
                   output: ["0", event.target.textContent],
                   hasComma: true
                }, () => console.log("state", this.state))             
             } else if (operator && parseInt(this.state.tempInput[0]) > 0) {
                // If an operation is selected, add zero before comma
                this.setState({
                   tempInput: [...tempInput, event.target.textContent],
                   output: [...tempInput, event.target.textContent],
                   hasComma: true
                }, () => console.log("state", this.state))             
             }
             break
          case "0":
             if (!this.state.input.length && !hasComma) {
                // If input is empty and there is no comma
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent]
                }, () => console.log("state", this.state))
               
             } else if (this.state.input[0] == "0" && this.state.input[1] == ".") {
                // If input is "0.", continue adding numbers
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent]
                }, () => console.log("state", this.state))
                
             } else if (this.state.input.length && hasComma && !operator) {
                // if there is some input and it's a decimal number
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent]
                }, () => console.log("state", this.state))
             } else if (this.state.input.length && hasComma && operator) {
                // if there is some input and it's a decimal number and a selected operator
                this.setState({
                   tempInput: [...tempInput, event.target.textContent],
                   output: [...tempInput, event.target.textContent],
                }, () => console.log("state", this.state))
             } else if (parseInt(this.state.input[0]) > 0 && !hasComma) {
                // if the input is a number, value is greater than 0, and is a whole number
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent]
                }, () => console.log("state", this.state)) 
             }
             break
          case "1":
          case "2":
          case "3":
          case "4":
          case "5":
          case "6":
          case "7":
          case "8":
          case "9":
             if (this.state.input[0] == "0" && !hasComma) {
                this.setState({
                   input: [event.target.textContent],
                   output: [event.target.textContent]
                }, () => console.log("state", this.state))
             } else if (operator) {
                this.setState({
                   tempInput: [...tempInput, event.target.textContent],
                   output: [...tempInput, event.target.textContent]
                }, () => console.log("state", this.state))
             } else {
                this.setState({
                   input: [...input, event.target.textContent],
                   output: [...input, event.target.textContent]
                }, () => console.log("statez", this.state))      
             }
             break
          default:
             this.setState({
                output: "ERROR"
             })
             break
       }
   }
   
   render() {
      const { output } = this.state
      return (
         <div className='container'>
            <div id="display">
               { output }
            </div>

            <div id="calculator" >
               <button id="clear" className="span-h red" onClick={() => this.clear()}>AC</button>
               <button id="divide" onClick={this.setOperator} className="gray">/</button>
               <button id="multiply" onClick={this.setOperator} className="gray">x</button>
               <button id="seven" onClick={this.getButtonValue}>7</button>
               <button id="eight" onClick={this.getButtonValue}>8</button>
               <button id="nine" onClick={this.getButtonValue}>9</button>
               <button id="subtract" onClick={this.setOperator} className="gray">-</button>
               <button id="four" onClick={this.getButtonValue}>4</button>
               <button id="five" onClick={this.getButtonValue}>5</button>
               <button id="six" onClick={this.getButtonValue}>6</button>
               <button id="add" onClick={this.setOperator} className="gray">+</button>
               <button id="one" onClick={this.getButtonValue}>1</button>
               <button id="two" onClick={this.getButtonValue}>2</button>
               <button id="three" onClick={this.getButtonValue}>3</button>
               <button id="equals" onClick={this.equate} className="span-v gray">=</button>
               <button id="zero" onClick={this.getButtonValue} className="span-h">0</button>
               <button id="decimal" onClick={this.getButtonValue} className="gray">.</button>
            </div>
         </div>

      )
   }
}

ReactDOM.render(
   <Calculator />,
   document.getElementById('app')
)
*/

              
            
!
999px

Console