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
Sample Input 1
120
6
Sample Output 1
20
Sample Input 2
5000
20
Sample Output 2
250
i want code in between write your code here
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
function Ride(fare, distance) {
/* Write your code here */
}
/* Please do not modify anything below this line */
function main() {
const fare = JSON.parse(readLine());
const distance = JSON.parse(readLine());
const ride1 = new Ride(fare, distance);
console.log(ride1.getFarePerKilometer());
}
"use strict";
process.stdin.resume();
process.stdin.setEncoding("utf-8");
let inputString = "";
let currentLine = 0;
process.stdin.on("data", (inputStdin) => {
inputString += inputStdin;
});
process.stdin.on("end", (_) => {
inputString = inputString.trim().split("\n").map((str) => str.trim());
main();
});
function readLine() {
return inputString[currentLine++];
}
/* Please do not modify anything above this line */
function Ride(fare, distance) {
/* Write your code here */
this.fare = fare;
this.distance = distance;
this.getFarePerKilometer = () => {
return `Fare Per Kilometer = ${this.fare / this.distance}`
}
}
/* Please do not modify anything below this line */
function main() {
const fare = JSON.parse(readLine());
const distance = JSON.parse(readLine());
const ride1 = new Ride(fare, distance);
console.log(ride1.getFarePerKilometer());
}
Comments
Leave a comment