-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbmiCalculator.js
More file actions
54 lines (47 loc) · 1.21 KB
/
Copy pathbmiCalculator.js
File metadata and controls
54 lines (47 loc) · 1.21 KB
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
import { LightningElement } from 'lwc';
export default class BmiCalculator extends LightningElement {
height = ''
weight = ''
bmiValue=''
result=''
inputHandler(event){
const {name, value} = event.target
if(name === "height"){
this.height = value
}
if(name === "weight"){
this.weight = value
}
/*** */
//this[name] = value
}
submitHandler(event){
event.preventDefault()
console.log("height", this.height)
console.log("weight", this.weight)
this.calculate()
}
calculate(){
//BMI = weight in KG / (height in m * height in m)
let height = Number(this.height)/100;
let bmi = Number(this.weight) /(height*height);
this.bmiValue = Number(bmi.toFixed(2))
if(this.bmiValue <18.5){
this.result = "Underweight"
} else if(this.bmiValue >=18.5 && this.bmiValue <25){
this.result = "Healthy"
} else if(this.bmiValue >=25 && this.bmiValue <30){
this.result = "Overweight"
} else {
this.result = "Obese"
}
console.log("BMI Value is : ", this.bmiValue)
console.log("Result is : ", this.result)
}
recalculate(){
this.height = ''
this.weight = ''
this.bmiValue=''
this.result=''
}
}