-
Notifications
You must be signed in to change notification settings - Fork 65
/
W2D1-Answers.txt
50 lines (35 loc) · 1002 Bytes
/
W2D1-Answers.txt
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
//: # W2D1 - Functions
//:
//: ## Challenge 1
greet(name: "Cory")
greet(name: "Danny")
//: ## Challenge 2
func pluralize(bicycleCount: Int) {
if bicycleCount == 1 {
print("There is \(bicycleCount) bicycle")
} else if (bicycleCount == 0) {
print("There are zero bicycles")
} else {
print("There are \(bicycleCount) bicycles")
}
}
//: ## Challenge 3
func pluralizedString(bicycleCount: Int) -> String {
if bicycleCount == 1 {
return "There is \(bicycleCount) bicycle"
} else if (bicycleCount == 0) {
return "There are zero bicycles"
} else {
return "There are \(bicycleCount) bicycles"
}
}
//: ## Bonus Challenge
func pluralizedWord(singular: String, pluralNoun: String, count: Int) -> String {
if count == 1 {
return "There is \(count) \(singular)"
} else if (count == 0) {
return "There are zero \(pluralNoun)"
} else {
return "There are \(count) \(pluralNoun)"
}
}