renamed 'input' to 'main'
This commit is contained in:
parent
38d008b050
commit
15e2006548
|
@ -3,7 +3,7 @@ import NumPad from "./NumPad";
|
||||||
import Operators from "./Operators";
|
import Operators from "./Operators";
|
||||||
|
|
||||||
export default function Calculator(props){
|
export default function Calculator(props){
|
||||||
const [input,setInput] = useState(0)
|
const [main,setMain] = useState(0)
|
||||||
const [memory,setMemory] = useState(0)
|
const [memory,setMemory] = useState(0)
|
||||||
const [operation,setOperation] = useState("")
|
const [operation,setOperation] = useState("")
|
||||||
|
|
||||||
|
@ -12,18 +12,19 @@ export default function Calculator(props){
|
||||||
|
|
||||||
|
|
||||||
function handleInput(content){
|
function handleInput(content){
|
||||||
|
|
||||||
const operations = {
|
const operations = {
|
||||||
"+":(a,b)=>{return a+b},
|
"+":(a,b)=>{return a+b},
|
||||||
"-":(a,b)=>{return a-b},
|
"-":(a,b)=>{return a-b},
|
||||||
"X":(a,b)=>{return a*b},
|
"X":(a,b)=>{return a*b},
|
||||||
"/":(a,b)=>{return a/b},
|
"/":(a,b)=>{return a/b},
|
||||||
}
|
}
|
||||||
|
|
||||||
if(typeof content === "number" ){
|
if(typeof content === "number" ){
|
||||||
setInput(prev=>{return prev.toString()+content.toString()})
|
setMain(prev=>{return prev.toString()+content.toString()})
|
||||||
}else{ //EXTRA CONDITION FOR DECIMAL, REGEX TO MAKE IT MAKE SENSE
|
}else{ //EXTRA CONDITION FOR DECIMAL, REGEX TO MAKE IT MAKE SENSE
|
||||||
setMemory(prev=>{operations[content](prev,input)})
|
setMemory(prev=>{operations[content](prev,main)})
|
||||||
setInput(0)
|
setMain(0)
|
||||||
setOperation(content)
|
setOperation(content)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -33,11 +34,11 @@ export default function Calculator(props){
|
||||||
<>
|
<>
|
||||||
<div id="display">
|
<div id="display">
|
||||||
<p id="memory">{memory}</p>
|
<p id="memory">{memory}</p>
|
||||||
<p id="input">{input}</p>
|
<p id="main">{main}</p>
|
||||||
<p id="operation">{operation}</p>
|
<p id="operation">{operation}</p>
|
||||||
</div>
|
</div>
|
||||||
<NumPad handleInput={handleInput}/>
|
<NumPad handlemain={handlemain}/>
|
||||||
<Operators handleInput={handleInput}/>
|
<Operators handlemain={handlemain}/>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
Loading…
Reference in New Issue