-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathContents.swift
24 lines (19 loc) · 965 Bytes
/
Contents.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import UIKit
// App Exercise - Separating Functions
func calculatePace(currentDistance: Double, totalDistance: Double, currentTime: Double) -> Double {
let remainingDistance = totalDistance - currentDistance
let currentSpeed = currentDistance / currentTime
return remainingDistance / currentSpeed
}
var calculatePaceResult = calculatePace(currentDistance: 5, totalDistance: 10, currentTime: 30)
print(calculatePaceResult)
func pacing2(currentDistance: Double, totalDistance: Double, currentTime: Double, goalTime: Double) -> String {
let timeRemaining = calculatePace(currentDistance: currentDistance, totalDistance: totalDistance, currentTime: currentTime)
if (currentTime + timeRemaining) <= goalTime {
return "Keep it up!"
} else {
return "You've got to push it just a bit harder!"
}
}
var pacingReturnValue = pacing2(currentDistance: 5, totalDistance: 10, currentTime: 30, goalTime: 50)
print(pacingReturnValue)