Created
July 11, 2020 03:22
-
-
Save mambodin/adc84aa56a6fbe18f5c8f32a4b67444d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, {useState, useEffect} from 'react'; | |
import '../Css/Calculator.css' | |
const Calculator = () => { | |
let [result, setResultState] = useState(0) | |
let [inputDisplay, setInputDisplayState] = useState(0) | |
let buttonHandler = (num) =>{ | |
if (inputDisplay === 0){ | |
setInputDisplayState( | |
inputDisplay = String(num) | |
) | |
} | |
else { | |
setInputDisplayState( | |
inputDisplay += String(num) | |
) | |
} | |
} | |
let evaluateResult = ()=>{ | |
} | |
return ( | |
<div> | |
<div className='header'> | |
<h2>{result}</h2> | |
<h1>{inputDisplay}</h1> | |
</div> | |
<div> | |
<button onClick={()=>buttonHandler('1')}>1</button> | |
<button onClick={() => buttonHandler('2')}>2</button> | |
<button onClick={() => buttonHandler('3')}>3</button> | |
<button onClick={() => buttonHandler('+')}>+</button> | |
<button onClick={evaluateResult}>=</button> | |
</div> | |
</div> | |
) | |
}; | |
export default Calculator; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment