-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathApp.js
50 lines (47 loc) · 1.65 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
import React, {Component} from 'react';
import {Text, View, Button, TextInput, Alert} from 'react-native';
import {Styles} from './Styles';
export default class App extends Component{
constructor(){
super();
this.state = {
weight: 0,
height: 0,
bmi: 0
}
}
calculateBMI = () => {
let totalBMI = Number((this.state.weight/Math.pow(this.state.height,2)) * 10000).toFixed(1);
this.setState({bmi: totalBMI}, () => {
if(this.state.bmi < 18.5){
Alert.alert('You are underweight!');
} else if(this.state.bmi >= 18.5 && this.state.bmi <= 24.9){
Alert.alert('You are having a normal weight. Well done!');
} else if(this.state.bmi >= 25 && this.state.bmi <= 29.9){
Alert.alert('You are overweight!');
} else if(this.state.bmi >= 30){
Alert.alert('You are obese. Please watch your diet!');
}
});
}
render() {
return (
<View style={Styles.container}>
<View style={Styles.container}>
<Text style={Styles.welcome}>BMI Calculator</Text>
</View>
<View style={Styles.container}>
<TextInput onChangeText={(weight) => this.setState({weight})} style={Styles.instructions} placeholder='Weight in KG'/>
<TextInput onChangeText={(height) => this.setState({height})} style={Styles.instructions} placeholder='Height in CM'/>
<Text></Text>
<Text></Text>
</View>
<View style={Styles.container}>
<Button color="#841584" onPress={this.calculateBMI} title='Calculate'/>
<Text></Text>
<Text style={Styles.instructions}>BMI: {this.state.bmi}</Text>
</View>
</View>
);
}
}