i am on iteration 4 of this attempt at this converter and i think i have most of the algorithms. I thnk i covered most of the error cases as well. What is crazy is that it is not passing the 3 tests that i thought would pass easiest, which is the actual number conversion. i am logging inputs and i cant tell why they are not passing as it looks like it is all functional to the tests.
any help would be appreciated.
below is my replit
https://replit.com/@RobertWisnewski/boilerplate-project-metricimpconverter#server.js
I cant figure out why some of my challenges are failing. To me, it seems as if i should be passing everything except for the functional tests.
im stumped
i have every test passing except the ‘lbs to kg’ test.
As it is right now, i have it converting exactly as everything else. But then i noticed that it says that it should convert to
’ Failed:You can convert 'lbs'
to 'kg'
and vice versa. (1 lbs to 0.453592 kg)’
which is 6 past the decimal point. so i tried adding the code below as the convert function
this.convert = function(initNum, initUnit) {
const galToL = 3.78541;
const lbsToKg = 0.453592;
const miToKm = 1.60934;
const init = initUnit
let result
if(init == 'lbs' || init == 'kg'){
switch(initUnit){
case 'kg':
result = initNum/lbsToKg.toFixed(6);
break;
case 'lbs':
result = initNum*lbsToKg.toFixed(6);
break;
}
return parseFloat(result.toFixed(6))
} else {
switch(initUnit){
case 'gal':
result = initNum*galToL.toFixed(5);
break;
case 'L':
result = initNum/galToL.toFixed(5);
break;
case 'mi':
result = initNum*miToKm.toFixed(5);
break;
case 'km':
result = initNum/miToKm.toFixed(5);
break;
default:
return undefined;
break;
}
return parseFloat(result.toFixed(5))
}
};
but it still failed
i have no idea. I may skip trying to figure out this last test and move to the next challenge and see if what i learn in them helps with this one.
suggestions?
system
Closed
December 29, 2022, 6:28am
4
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.