Fare per Kilometer
Given total fare
fare and distance travelled in kilometers distance for a rental bike, write a JS constructor function with a method to calculate the fare per kilometer.
Quick Tip
The formula to calculate the fare per kilometer is,
fare per kilometer = fare / distance
The first line of input contains a number
The output should be a single line containing the fare per kilometer
function farePerKilometer(fare, distanceOutput) {
return fare / distanceOutput
}
let fare = 200;
let distanceOutput = 20;
console.log('fare per kilometer = ' + farePerKilometer(fare, distanceOutput) );
Comments
Leave a comment