JSFiddle - React, Tailwind, and code Playground

by velmurugansp

JavaScript

// If a person walks at 14 km/hr instead of 10 km/hr, he would have walked 20 km more. The actual distance travelled by him is:

var speed1 = 7;

var speed2 = 5;

var distance1 = 30;

var distance2;

// 14 x = (x + 20) * 10

// 14 * x = (10 * x) + (10 * 20)

// 14 * x - (10 * x) =  (10 * 20);

// (14 - 10) * x = 10 * 20;

// x = (10 * 20) / (14 - 10);

distance2 = (speed2 * distance1) / (speed1 - speed2);


var question = "If a person walks at " + speed1 + " km/hr instead of " + speed2 + " km/hr, he would have walked " + distance1 + " km more. The actual distance travelled by him is:" 

console.log(question);

var answer = distance2 + " km";

console.log(answer);