Answer to Question #170266 in HTML/JavaScript Web Application for mani

Question #170266

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

Input

The first line of input contains a number

fare The second line of input contains a number distance
Output

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());

}


1
Expert's answer
2021-03-09T03:02:59-0500
"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());
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS