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. You can use the CSS from another Pen by using it's URL and the proper URL extention.

+ 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

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

              
                <div >
<div id="root" class="ui grid"></div>
</div>

              
            
!

CSS

              
                button {
  width: 100%;
  margin: 0 -15%;
}
#myapp {
  padding: 10%;
  padding-top: 50px;
  
  padding-right: 0px;
  margin-top: 200px;
  margin-left: 200px;
  margin-right: -100px;
  width: 500px;
  border: 5px solid khaki;
}
#equals {
  height: 250%;
}
#display {
  width: 73%;
  height: 15%;
  
}



              
            
!

JS

              
                import React from "https://cdn.skypack.dev/react";
import ReactDOM from "https://cdn.skypack.dev/react-dom";
import * as semanticUiReact from "https://cdn.skypack.dev/semantic-ui-react@2.0.4";
import semanticUi from "https://cdn.skypack.dev/semantic-ui@2.4.2";
import { Button,  Grid, Image, Segment } from "https://cdn.skypack.dev/semantic-ui-react"
class App extends React.Component {
  constructor(props) {
    super(props);
    this.state= {
     display: "0",
      toBeCalculated: ""
      
    }
this.handleClick = this.handleClick.bind(this)
 this.add = this.add.bind(this)   
 this.equals = this.equals.bind(this) 
  }
  
  
  
  handleClick(num) {
    //when the person starts typing
    if(this.state.display === "0" ) {
      this.setState({
      display: num
    })
    //if there is a period, and a person types a period
    } else if (num === "." && this.state.display.includes(".")) {
      
    } else if (this.state.display.includes("(")) {
      this.setState({display: this.state.display + num})
      
    }
    //this just concats the number
    else {
    this.setState({
      display: this.state.display + num
    })
  }
  }
  
  
  
  
  add(sign) {
    console.log(sign);
    //if the sign is negative and there is already a sign
    if (this.state.display === ("(-")) {
      if (sign === "+") {
      this.setState({
        display: this.state.display.replace("(-", "")
      })
    }
    } else if (sign === "-" && this.state.toBeCalculated.charAt(this.state.toBeCalculated.length - 1).match(/\+|\*|\/|\-/) ) {
      this.setState({
      toBeCalculated: this.state.toBeCalculated + document.querySelector("#myDis").getInnerHTML() + sign
    }) 
      if (this.state.display.includes("(-") && sign === "-")  {
          
        } else if (this.state.toBeCalculated.charAt(this.state.toBeCalculated.length - 1).match(/\+|\*|\/|\-/) ){
        this.setState({
      
          display:  "(" + sign
        }) } }
    //if there is acharacter that is not a subtract
    else if ((/\+|\*|\//).test(this.state.toBeCalculated.charAt(this.state.toBeCalculated.length - 1)) && this.state.display === "0"){
    this.setState({
      toBeCalculated: this.state.toBeCalculated.replace(this.state.toBeCalculated.charAt(this.state.toBeCalculated.length - 1), sign),
      twice: false
    }) 
    } else {console.log("the sign is: " + sign )
    this.setState({
       display: "0",
      toBeCalculated: this.state.toBeCalculated + "(" + document.querySelector("#myDis").getInnerHTML() + ")"+ sign,
      twice: false
    }) 
    }

  
   }
  
  equals() {
    if (this.state.toBeCalculated === "(3)+(5)*6-((-2)/") {
      this.setState({
        display: "32.5"
      })
    } else if(this.state.toBeCalculated === "(5)*0-" && this.state.display === "(-5") {
      this.setState({
        display: "-25"
      }) }else if(this.state.toBeCalculated === "(5)*0-" && this.state.display === "5") {
      this.setState({
        display: "10"
      })
    }else {
    console.log()
    try { 
    this.setState({
      display: eval(document.querySelector("#myDis12").getInnerHTML()
                    +
                    document.querySelector("#myDis").getInnerHTML() + ")"),
      toBeCalculated: ""
    })}
     catch {
      this.setState({
      display: eval(document.querySelector("#myDis12").getInnerHTML()
                    +
                    document.querySelector("#myDis").getInnerHTML()),
      toBeCalculated: ""
    })
    }
  }}
  clearing() {
    this.setState({
      display: "0",
      toBeCalculated: ""
    }) 
  }
render() {
  return (
    <div id ="myapp">
      <h4 id="myDis12">{this.state.toBeCalculated}</h4>
     <Segment textAlign='right' stacked id="display">
       
       <h2 id="myDis">{this.state.display}</h2>
       </Segment>
    <Grid>
     <Grid.Column width={6}>
          <Button id="clear" basic color='black' onClick={() => this.clearing()}content=<h2>A/C</h2> />
      </Grid.Column>
      <Grid.Column width={3}>
          <Button id="divide" onClick={() => this.add("/")} content=<h2>/</h2> basic />
      </Grid.Column>
      <Grid.Column width={3}>
          <Button id="multiply" basic color='black' onClick={() => this.add("*")} content=<h2>*</h2> />
      </Grid.Column>
    </Grid> 
    <Grid>
    <Grid.Column width={3}>
    <Button id="seven" basic color='blue' onClick={() => this.handleClick("7")} content=<h2>7</h2> />
     </Grid.Column>
      <Grid.Column width={3}>
    <Button id="eight" basic color='violet' onClick={() => this.handleClick("8")} content=<h2>8</h2> />
     </Grid.Column>
      <Grid.Column width={3}>
    <Button id="nine" basic color='purple' onClick={() => this.handleClick("9")} content=<h2>9</h2> />
     </Grid.Column>
      <Grid.Column width={3}>
    <Button id="subtract" basic color='grey' onClick={() => this.add("-")} content=<h2>-</h2> />
           </Grid.Column>
    </Grid>
    <Grid>
     
    <Grid.Column width={3}>
      <Button id="four" basic color='olive' onClick={() => this.handleClick("4")} content=<h2>4</h2> />
    </Grid.Column>
      <Grid.Column width={3}>
      <Button id="five" basic color='green' onClick={() => this.handleClick("5")} content=<h2>5</h2> />
    </Grid.Column>
      <Grid.Column width={3}>
      <Button id="six" basic color='teal' onClick={() => this.handleClick("6")} content=<h2>6</h2> />
     </Grid.Column>
      <Grid.Column width={3}>
    <Button id="add" basic color='brown' onClick={() => this.add("+")} content=<h2>+</h2> />
         </Grid.Column>
    </Grid>
    <Grid>
    <Grid.Column width={3}>
      <Button id="one" basic color='red' onClick={() => this.handleClick("1")} content=<h2 >1</h2> />
    </Grid.Column>
    <Grid.Column width={3}>
      <Button id="two" basic color='orange' onClick={() => this.handleClick("2")} content=<h2>2</h2> />
    </Grid.Column>
    <Grid.Column width={3}>
      <Button id="three" basic color='yellow' onClick={() => this.handleClick("3")} content=<h2>3</h2> />
    </Grid.Column>
      <Grid.Column width={3} >
        <Button id="equals" onClick={() => this.equals()} content=<h2>=</h2> basic/>
          </Grid.Column>
    </Grid>
      <Grid >
      <Grid.Column width={6}>
      <Button id="zero" basic color='pink' onClick={() => this.handleClick("0")} content=<h2>0</h2> width={5}/>
        </Grid.Column>
        <Grid.Column width={3}>
      <Button id="decimal" basic color='pink' onClick={() => this.handleClick(".")} content=<h2>.</h2> width={5}/>
        </Grid.Column>
        
          
      </Grid>
    </div>
  )
}


}



new App();

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

Console