Answer the question
In order to leave comments, you need to log in
How to get the sum of three inputs?
How to get and show the sum of three inputs?
There is a main component in which 3 inputs are collected (type: range) and a Total component in which you need to display the sum of the values of the inputs. Here is my sketch:
Main.js
export default function Main() {
<div className='ranges df'>
<RangeInput
id={'height'}
min={50}
max={220}
label={'height (sm)'}
lng={'lng-height'}
/>
<RangeInput
id={'weight'}
min={1}
max={200}
label={'weight (kg)'}
lng={'lng-weight'}
/>
<RangeInput
id={'age'}
min={1}
max={110}
label={'age'}
lng={'lng-age'}
/>
<Total />
</div>
}
export default function RangeInput({ id, max, min, label, lng }) {
const [state, setState] = useState(Math.floor((max + min) / 2));
return (
<div className='range'>
<div className={
state !== Math.floor((max + min) / 2) ? 'output changed' : 'output'
}>
{state}
</div>
<input
id={id}
type='range'
min={min}
max={max}
step='1'
defaultValue='50%'
onChange={(event) => setState(event.target.value)}
/>
<h4 className={lng}>{label}</h4>
</div>
);
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question