문제
우리는 마일/갤런 단위의 숫자를 입력받아 이에 상응하는 km/리터를 반환하는 JavaScript 함수를 작성해야 합니다.
예시
다음은 코드입니다 -
const num = 25;
const converter = (mpg) => {
let LITRES_PER_GALLON = 4.54609188;
let KILOMETERS_PER_MILE = 1.609344;
const ratio = KILOMETERS_PER_MILE / LITRES_PER_GALLON;
return Math.round(100 * mpg * ratio) / 100;
};
console.log(converter(num)); 출력
다음은 콘솔 출력입니다 -
8.85