[英]How can I keep track if runner is on pace in fitness tracking app?
I am going through the challenges in Apple's "App Development With Swift" iBook and have hit a roadblock in completing the fitness app in Lesson 2.2 - Functions. 我正在经历苹果公司的“使用Swift开发应用程序” iBook中遇到的挑战,并且在完成第2.2课-函数中完成健身应用程序遇到了障碍。 I can't think of a good formula to track if the user is on pace or not.
我想不出一个跟踪用户是否步调良好的公式。 I am still a noob and this is so far what I have come up with which obviously doesn't accurately keep track of the pace.
我仍然是一个菜鸟,到目前为止,这是我的想法,显然无法准确跟踪进度。
func pacing(currentDistance: Double, totalDistance: Double, currentTime: Double, goalTime: Double) {
if (currentDistance < 0.50 * totalDistance && currentTime > 0.40 * goalTime) {
print("You've got to push it just a bit harder!")
}
else {
print("Keep it up!")
}
}
pacing(currentDistance: 1, totalDistance: 10, currentTime: 8, goalTime:60)
The challenge in the book tells you to do the following: Your fitness tracking app is going to help runners stay on pace to reach their goals. 书中的挑战告诉您要执行以下操作:您的健身跟踪应用程序将帮助跑步者保持步伐以实现自己的目标。 Write a function called pacing that takes four Double parameters called currentDistance, totalDistance, currentTime, and goalTime.
编写一个名为pacing的函数,该函数接受四个Double参数,分别称为currentDistance,totalDistance,currentTime和GoalTime。 Your function should calculate whether or not the user is on pace to hit or beat goalTime.
您的函数应计算用户是否在达到或击败目标时间上。 If yes, print "Keep it up!", otherwise print "You've got to push it just a bit harder!"
如果是,请打印“保持!”,否则请打印“您必须将其推得更紧一点!”
As we know that Distance = Speed * Time , so here you want to know that what is the current speed and based on that you would print the appropriate message So you can try something like this: 我们知道Distance = Speed * Time,所以在这里您想知道当前速度是多少,并在此基础上打印相应的消息,因此可以尝试如下操作:
func pacing(currentDistance: Double, totalDistance: Double, currentTime: Double, goalTime: Double) {
let goalSpeed = totalDistance / goalTime
let currentSpeed = currentDistance / currentTime
if (currentSpeed < goalSpeed) {
print("You've got to push it just a bit harder!")
}
else {
print("Keep it up!")
}
}
pacing(currentDistance: 1, totalDistance: 10, currentTime: 8, goalTime:60)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.