import React, { useState } from "react";
export default function App() {
const [pointsGiven, setPointsGiven] = useState(0);
const [pointsPossible, setPointsPossible] = useState(0);
const [percentage, setPercentage] = useState(0);
const calculate = (e) => {
e.preventDefault();
const formValid = +pointsGiven >= 0 && +pointsPossible > 0;
if (!formValid) {
return;
}
setPercentage((+pointsGiven / +pointsPossible) * 100);
};
return (
<div className="App">
<form onSubmit={calculate}>
<div>
<label>points given</label>
<input
value={pointsGiven}
onChange={(e) => setPointsGiven(e.target.value)}
/>
</div>
<div>
<label>points possible</label>
<input
value={pointsPossible}
onChange={(e) => setPointsPossible(e.target.value)}
/>
</div>
<button type="submit">calculate</button>
</form>
<div>percentage:{percentage}</div>
</div>
);
}
Code Example |
---|
Javascript :: update nested formgroup angular |
:: Working of JavaScript Arrays |
:: await javascript |
:: |
:: |
:: switch19 dynamically update js |
:: |
Javascript :: |
:: javascript remove element from array in foreach |
:: js Arrays indexOf |
:: list in react native |
:: javascipt async |
:: how to set variable in discord.js |
:: |
Javascript :: JavaScript substring Syntax |
Javascript :: indexof javascript |
Javascript :: |
:: setinterval on and off |
:: |
:: |
Javascript :: |
Javascript :: |
:: vue send data between components |
Javascript :: firebase rules for specific user |
:: |
Javascript :: |
:: set default value in dropdown angular 7 |
:: js electron setup |
:: how to select a dom element in react |
Javascript :: string object javascript |