Need help solving this quick exercise. Can\'t seem to grasp what the code would
ID: 3736695 • Letter: N
Question
Need help solving this quick exercise. Can't seem to grasp what the code would look like.
This is the best I got for an answer:
halfway = steps > (stepGoal / 2) ? print("Over halfway!") : print("Almost halfway!")
I'm trying to tell the program - if steps are greater than half the goal, then print "Over halfway!," if not, then print "Almost halfway!"
Thanks for any advice!
App Exercise - Ternary Messages Note These exercises reinforce Swift concepts in the context of a fitness tracking app. The code below should look similar to code you wrote in the Fitness Decisions exercise. The if-else statement is actually unnecessary, and instead you can print either one statement or the other all on one line using the ternary operator. Go ahead and refactor the code below to do just that let stepGoal 10008 let steps-3948 10 11 if stepsExplanation / Answer
We can write it as:
print(steps > stepGoal/2 ? "Over halfway" : "Almost halfway")
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.