Converting km per hour to cm per second using JavaScript

JavascriptWeb DevelopmentFront End Technology

Problem

We are required to write a JavaScript function that takes in a number that specifies speed in kmph and it should return the equivalent speed in cm/s.

Example

Following is the code −

 Live Demo

const kmph = 12;
const convertSpeed = (kmph) => {
   const secsInHour = 3600;
   const centimetersInKilometers = 100000;
   const speed = Math.floor((kmph * centimetersInKilometers) / secsInHour);
   return `Equivalent in cmps is: ${speed}`;
};
console.log(convertSpeed(kmph));

Output

Equivalent in cmps is: 333
raja
Published on 17-Apr-2021 13:33:36
Advertisements