Converting km per hour to cm per second using JavaScript



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
Updated on: 2021-04-17T13:38:13+05:30

696 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements