Skip to content

Commit

Permalink
Merge pull request #615 from 1520229462/master
Browse files Browse the repository at this point in the history
Golden Ratio Calculator
  • Loading branch information
SarthakKeshari authored Oct 31, 2023
2 parents 66f0a7f + 8130dfa commit 687dea3
Showing 1 changed file with 82 additions and 10 deletions.
92 changes: 82 additions & 10 deletions calculators/src/mathematical/goldenRatioCalc/MainGoldenRatioCalc.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,91 @@
import React from 'react';
import React, { useEffect, useState } from 'react';
import { Container, Typography } from '@mui/material';
import TextField from '@mui/material/TextField';
import Button from '@mui/material/Button';

function MainGoldenRatioCalc(){
return(
<Container maxWidth="lg" sx={{ bgcolor: '#eeeeee', minHeight: '90vh', paddingY:"10" }}>
<Typography pt={1} variant='h5' sx = {{textAlign: "center"}}>Golden Ratio Calculator</Typography>
<hr/>
<br/>
{/* Write your code here */}

function MainGoldenRatioCalc() {

const [sum, setSum] = useState('');
const [a, setA] = useState('');
const [b, setB] = useState('');

{/* End your code here */}
const ableTextFields = () => {
document.querySelectorAll('input[type="text"]').forEach((input) => {
input.disabled = false;
});
};

const handleClear = () => {
setSum('');
setA('');
setB('');
ableTextFields();
};

useEffect(() => {
if ( (a !== '' && !isNaN(a)) && (b !== '' && !isNaN(b) )) {
setSum(a + b);
} else if ((a !== '' && !isNaN(a)) && (sum !== '' && !isNaN(sum))) {
setB(sum - a)
} else if ((sum !== '' && !isNaN(sum)) && (b !== '' && !isNaN(b))) {
setA(sum - b);
}

}, [sum,a,b]);

const handleA = (e) => {
setA(parseFloat(e.target.value));
};

const handleB = (e) => {
setB(parseFloat(e.target.value));
};

const handleSum = (e) => {
setSum(parseFloat(e.target.value));
};

return (
<Container maxWidth="lg" sx={{ bgcolor: '#eeeeee', minHeight: '90vh', paddingY: "10" }}>
<Typography pt={1} variant='h5' sx={{ textAlign: "center" }}>Golden Ratio Calculator</Typography>
<hr />
<br />

<TextField
label="Value of A+B"
type="number"
value={sum || ''}
onChange={ handleSum}


/>
<TextField
label="Value of A"
type="number"
value={a || ''}
onChange={ handleA}


/>
<TextField
label="Value of B"
type="number"
value={b || ''}
onChange={ handleB}

/>
<Typography variant="h6" sx={{ marginTop: '2rem', textAlign: 'center' }}>
(A+B:A) {(sum / a) || ''} = (A:B) {(a / b) || ''}
</Typography>

<Button variant="contained" onClick={handleClear}>Clear</Button>




</Container>
)
}

export default MainGoldenRatioCalc;
export default MainGoldenRatioCalc;

0 comments on commit 687dea3

Please sign in to comment.