Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
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 −
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
Advertisements
