Firstly, i wanna assign numbers to all alphabets like this:
a=1,b=2,c=3,d=4
etc.Secondly, I want to create an input field and submit Button.
Thirdly, when I enter alphabets on that input field, (eg: abcd it shows 1234 because i already mentioned above, a=1, b=2, c=3, d=4).
And last, I wanna to add them (eg: I entered "abcd" and output is 1234 and add them.)Final Output for abcd is 1+2+3+4 =10.
import React,{useState} from 'react' import "../node_modules/bootstrap/dist/css/bootstrap.min.css"
const Data = () => { const [data, setData] = useState({a: 1,b: 2,c: 3,d: 4,e: 5,f: 6,g: 7,h: 8,i: 9,j: 10,k: 11,l: 12,m: 13,n: 14,o: 15,p: 16,q: 17,r: 18,s: 19,t: 20,u: 21,v: 22,w: 23,x: 24,y: 25,z: 26})
const changeHandler = e => {
setData({...data,[e.target.name]:[e.target.value]})
}
const submitHandler=e=> {
e.preventDefault();
}
return (
<div>
<form onSubmit={submitHandler}>
<input type="text"onChange={changeHandler}/><br/>
<button className="btn btn-primary"onClick={()=>setData(console.log(data))}>Click</button><br/>
</form>
</div>
) }
export default Data