Challenge: Simple Function Creation
Uppgift
Swipe to start coding
You are building a ride-sharing app. Each ride has a distance in kilometers, and you want to calculate the total cost based on a base fare and a per-kilometer rate.
- Declare the function
calculateTripCostthat returns adouble. - Add a parameter to the function with type
doublenameddistance. - Calculate the total cost by multiplying
distancebyperKmRateand adding thebaseFare. - Return the total cost from the function.
Do not modify the values of baseFare and perKmRate inside the calculateTripCost function.
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 1. Kapitel 3
single
Fråga AI
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal
Fantastiskt!
Completion betyg förbättrat till 5.26
Challenge: Simple Function Creation
Svep för att visa menyn
Uppgift
Swipe to start coding
You are building a ride-sharing app. Each ride has a distance in kilometers, and you want to calculate the total cost based on a base fare and a per-kilometer rate.
- Declare the function
calculateTripCostthat returns adouble. - Add a parameter to the function with type
doublenameddistance. - Calculate the total cost by multiplying
distancebyperKmRateand adding thebaseFare. - Return the total cost from the function.
Do not modify the values of baseFare and perKmRate inside the calculateTripCost function.
Lösning
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 1. Kapitel 3
single