Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.1 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
69162d64f96574d9bb629efe Challenge 113: Miles to Kilometers 28 challenge-113

--description--

Given a distance in miles as a number, return the equivalent distance in kilometers.

  • The input will always be a non-negative number.
  • 1 mile equals 1.60934 kilometers.
  • Round the result to two decimal places.
  • Remove unnecessary trailing zeros from the rounded result.

--hints--

convertToKm(1) should return 1.61.

assert.equal(convertToKm(1), 1.61);

convertToKm(21) should return 33.8.

assert.equal(convertToKm(21), 33.8);

convertToKm(3.5) should return 5.63.

assert.equal(convertToKm(3.5), 5.63);

convertToKm(0) should return 0.

assert.equal(convertToKm(0), 0);

convertToKm(0.621371) should return 1.

assert.equal(convertToKm(0.621371), 1);

--seed--

--seed-contents--

function convertToKm(miles) {

  return miles;
}

--solutions--

function convertToKm(miles) {
  const km = miles * 1.60934;
  return Math.round(km * 100) / 100;
}