-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
87 lines (57 loc) · 1.46 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import './App.css';
import React,{useEffect, useState} from 'react';
function App() {
const [height,setHeight]=useState(null);
const [weight,setWeight]=useState(null);
const [bmi,setBmi]=useState('');
const [massage,setMassage]=useState('');
// logic bmi
const cal= () =>{
if(weight===0 || height===0){
alert("Enter valid weight and height ");
}
else{
let bmi=weight/height/ height*10000
setBmi(bmi.toFixed(1));
if(bmi<18){
setMassage("you are underweight");
}
else if(bmi>=18 && bmi<=25){
setMassage("you are healthy");
}
else {
setMassage("you are overweight ");
}
}
}
const handleSubmit =(e) =>{
e.preventDefault();
cal();
}
useEffect( () =>{
cal();
},[height,weight,cal])
return (
<div className="app">
<h1>Bmi Calculator</h1>
<form onSubmit={handleSubmit}>
<div className="lab1">
<lable>Height in(cm) : </lable>
<input type="number" value={height} onChange={(e)=>setHeight(e.target.value) } ></input>
</div>
<div className="lab1">
<lable>weight in(kg) : </lable>
<input type="number" value={weight} onChange={(event)=>setWeight(event.target.value) }></input>
</div>
<div className="center">
<button className="btn" type='submit'>Calculate</button>
</div>
<div className='massage'>
<h3>Your Bmi is :{bmi}</h3>
<p>{massage}</p>
</div>
</form>
</div>
);
}
export default App;