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

              
                <!-- 

Hello Camper!

Please read the README below in the JS Editor before beginning. Feel free to delete this message once you have read it. Good luck and Happy Coding! 

- The freeCodeCamp Team 

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

CSS

              
                * {
    box-sizing: border-box;
}
body {
    background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
    background-size: 400% 400%;
    animation: gradient 15s ease infinite;
    font-family: "Roboto", sans-serif;
}
.layout {
    background-color: rgba(63, 63, 63, 0.322);
    border-radius: 6px;
    height: 474px;
    width: 293px;
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
}
button {
    border: 1px solid rgba(90, 90, 90, 0.37);
    border-radius: 10px;
    font-size: 30px;
    height: 70px;
    width: 70px;
    margin: 1px;
    margin-bottom: 1px;
    cursor: pointer;
}

h1 {
    padding: 0px;
}

.button-wrapper {
    padding-top: 2px;
    padding-left: 2px;
}

#calc-container {
    height: 100vh;
}

#screen {
    background-color: rgb(255, 255, 255);
    color:black;
    border-radius: 10px;
    width: 98%;
    text-align: right;
    padding: 20px 10px;
    font-size: 35px;
    padding-top:5px;
    position: relative;
}

#display small {
    position: absolute;
    top: 15px;
    right: 5px;
    font-size:15px;
}
#logo {
    font-size: 12px;
}

#clear {
    width: 214px;
    background-color: #e73c7e;
    color: white;
}
#zero {
    width: 142px;
}

#equals {
    background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab);
    background-size: 400% 400%;
    animation: gradient 15s ease infinite;
    color: white;
}

#decimal {
    background-color: rgba(128, 128, 128, 0.377);
    color: white;
}
button.integers {
    background-color: #23a6d5;
    color: white;
}

button.operations {
    background-color: #ee7752;
    color: white;
}
button:hover {
    opacity: 0.7;
}

button:active {
    transform: scale(0.98);
}

button:focus {
    outline: none;
}


@keyframes gradient {
    0% {
        background-position: 0% 50%;
    }
    20% {
        background-position: 100% 50%;
    }
    40% {
        background-position: 0% 50%;
    }
    60% {
        background-position: 100% 50%;
    }
    80% {
        background-position: 0% 50%;
    }
    100% {
        background-position: 100% 50%;
    }
}
              
            
!

JS

              
                class App extends React.Component {
    state ={
        currentNumber: '0',
        calc: undefined,
        operation: undefined,
        sequence: undefined
    }

    handleClick = (event) => {
        const {currentNumber, calc, operation, sequence} = this.state;
        const {innerText} = event.target;

        if(!Number.isNaN(Number(innerText))) {
            if(currentNumber === '0') {
                this.setState({
                    currentNumber:innerText
                });
            } else {
                this.setState({
                    currentNumber: currentNumber + innerText
                });
            }

            return;
        }

        switch(innerText) {
            case 'AC': {
                this.setState({
                    currentNumber: '0',
                    calc: undefined,
                    operation: undefined,
                    sequence: undefined,
                    store: undefined
                });
                break;
             }

            case '.': {
                if(!currentNumber.includes('.')) {
                    this.setState({
                        currentNumber: currentNumber + innerText
                    });
                 };
                 break;
            }

            default: {
                if(!operation) { 
                    if(innerText === 'x') {
                        const bruh = '*'
                        this.setState({
                            operation: bruh,
                            calc: currentNumber,
                            sequence: currentNumber + innerText,
                            currentNumber: '0'
                        });
                    } 
                    else if (innerText === '÷') {
                        const pog = '/'
                        this.setState({
                            operation: pog,
                            calc: currentNumber,
                            sequence: currentNumber + innerText,
                            currentNumber: '0'
                        });
                    } else {
                        this.setState({
                            operation: innerText,
                            calc: currentNumber,
                            sequence: currentNumber + innerText,
                            currentNumber: '0'
                        });
                    }
                } else if (innerText === "=") {
                    const evaluated = eval(`${calc} ${operation} ${currentNumber}`);
                    this.setState({
                        operation: undefined,
                        calc: evaluated,
                        currentNumber: evaluated,
                        sequence: sequence + currentNumber + '='
                    });
                } else {
                    const evaluated = eval(`${calc} ${operation} ${currentNumber}`);
                    if(innerText === '-') {
                        this.setState({
                            currentNumber: '-'
                        })

                    } else {
                
                        if(innerText === 'x') {
                            const bruh = '*'
                            this.setState({
                                operation: bruh,
                                calc: evaluated,
                                currentNumber: '0',
                                sequence: sequence + currentNumber + innerText
                            });
                        } 
                        else if (innerText === '÷') {
                            const pog = '/'
                            this.setState({
                                operation: pog,
                                calc: evaluated,
                                currentNumber: '0',
                                sequence: sequence + currentNumber + innerText
                            });
                        } else {
                            this.setState({
                                operation: innerText,
                                calc: evaluated,
                                currentNumber: '0',
                                sequence: sequence + currentNumber + innerText
                            });
                        }   
                    } 
                }
            }
        }
    }

    render() {

        const {sequence, currentNumber, calc} = this.state;
        return(
        <div id="calc-container" className="d-flex align-items-center justify-content-center">
        <div className="layout">
            <div id="screen">
                <div id="logo" className="d-flex align-item-left">
                    <i className="fas fa-calculator"></i>Epic Calculator
                </div>
                <div id="display"><small>{sequence}</small>{currentNumber}</div>    
            </div>

            <div className="col-12 button-wrapper">
                <button id="clear" onClick={this.handleClick}>AC</button>
                <button id="divide" className="operations" onClick={this.handleClick}>÷</button>
                <button id="seven" className="integers" onClick={this.handleClick}>7</button>
                <button id="eight" className="integers" onClick={this.handleClick}>8</button>
                <button id="nine" className="integers" onClick={this.handleClick}>9</button>
                <button id="multiply"className="operations" onClick={this.handleClick}>x</button>
                <button id="four" className="integers" onClick={this.handleClick}>4</button>
                <button id="five" className="integers" onClick={this.handleClick}>5</button>
                <button id="six" className="integers" onClick={this.handleClick}>6</button> 
                <button id="subtract" className="operations" key={"-"} onClick={this.handleClick}>-</button>
                <button id="one" className="integers" onClick={this.handleClick}>1</button>
                <button id="two" className="integers" onClick={this.handleClick}>2</button>
                <button id="three" className="integers" onClick={this.handleClick}>3</button>
                <button id="add"className="operations" onClick={this.handleClick}>+</button>
                <button id="zero" className="integers" onClick={this.handleClick}>0</button>
                <button id="decimal" onClick={this.handleClick}>.</button>
                <button id="equals" key={"="} onClick={this.handleClick}>=</button>
            </div>
        </div>
        </div>
        )
    }

}


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

Console