Metric/Imperial Converter failing user stories but passing Chai tests

Hi All,

Probably missing something really silly here but my Metric/Imperial converter is failing 3 user stories while passing all tests and I can’t debug the error.

The failing tests are the actual conversion ones so I expect it’s something to do with the return value, I’ve tried returning the full number, a string fixed to 5 and a Number() of that string and none of it seems to be working.

You can convert 'gal' to 'L' and vice versa. (1 gal to 3.78541 L)

You can convert 'lbs' to 'kg' and vice versa. (1 lbs to 0.453592 kg)

You can convert 'mi' to 'km' and vice versa. (1 mi to 1.60934 km)

Your project link(s)

solution: https://boilerplate-project-metricimpconverter.anilsiv.repl.co

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36.

Challenge: Metric-Imperial Converter

Link to the challenge:

Fixed it, this was the code that finally worked if anyone runs into my mistake in the future!

 switch(initUnit) {
    case 'mi': return Number((initNum * miToKm).toFixed(5)); 
    case 'km': return Number((initNum / miToKm).toFixed(5));
    case 'lbs': return Number((initNum * lbsToKg).toFixed(5));
    case 'kg': return Number((initNum / lbsToKg).toFixed(5));
    case 'gal': return Number((initNum * galToL).toFixed(5));
    case 'l': return Number((initNum / galToL).toFixed(5)); 
    default:
      return 'unknown';
  }

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.