我们需要编写一个JavaScript函数,该函数接受以英里/加仑为单位的数字,并返回其等效的km / L。
以下是代码-
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