SectionΒ 1. ChapterΒ 48
single
Challenge: Fixing the Speed Function
Swipe to show menu
Task
Swipe to start coding
Previously, you created a calcSpeed function that calculated the speed of a car using fixed values inside the function.
Now you need to improve the function so that it can accept values from outside.
Your tasks:
- Remove the local variables
distanceandtimeTakenfrom inside the function. - Add two parameters named
distanceandtimeTakenin the function definition. - Calculate the speed using the formula:
Speed = Distance / Time Taken - Return the calculated speed.
- Call the function twice using the following arguments:
1000,1201200,160
Solution
Everything was clear?
Thanks for your feedback!
SectionΒ 1. ChapterΒ 48
single
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat