-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathApp.js
83 lines (77 loc) · 1.88 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
import React from "react";
import { StyleSheet, Text, View, TextInput, Image } from "react-native";
export default class App extends React.Component {
state = {
numRSVP: null
};
_calculateAttending(rsvpCount) {
let attendingCount =
rsvpCount > 10 ? 0.8 * (rsvpCount - 10) + 10 : rsvpCount;
return parseInt(attendingCount);
}
calculatePizzaOrder(rsvpCount) {
let actualAttending = this._calculateAttending(rsvpCount);
if (actualAttending) {
let pizzaCount =
actualAttending > 10
? actualAttending / (20 / 3) + 1.5
: actualAttending / (10 / 3);
return `${Math.ceil(pizzaCount)} 🍕`;
}
}
render() {
return (
<View style={styles.container}>
<View style={styles.appBar} />
<View style={styles.jumbotronContainer}>
<Text style={styles.jumbotronText}>
{this.calculatePizzaOrder(this.state.numRSVP)}
</Text>
</View>
<Text style={styles.label}>Enter the number of Meetup RSVP's</Text>
<TextInput
style={styles.input}
keyboardType="number-pad"
onChangeText={numRSVP => this.setState({ numRSVP })}
value={this.state.numRSVP}
placeholder="Enter a number"
autoFocus
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flexDirection: "column",
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center"
},
appBar: {
height: 20
},
jumbotronContainer: {
marginTop: 30,
borderWidth: 1,
borderColor: "#ddd",
height: 200,
width: 300,
justifyContent: "center"
},
jumbotronText: {
textAlign: "center",
fontSize: 72,
color: "red"
},
label: {
marginTop: 30,
marginBottom: 15
},
input: {
height: 40,
borderBottomColor: "#ddd",
borderBottomWidth: 1,
width: 300
}
});