Metric-Imperial Converter Fraction 10th test not passing

Tell us what’s happening:
I’m not able to pass the test:

  • You can use fractions, decimals or both in the parameter (ie. 5, 1/2, 2.5/6), but if nothing is provided it will default to 1.

This is the error from the console:

Your project link(s)

solution: https://replit.com/@Ry2uko/Metric-Imperial-Converter

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0

Challenge: Metric-Imperial Converter

Link to the challenge:

Log the route input and output that you are returning and the failing one looks like

req.query: {"input":"1/5mi"}
{
  initNum: '0.20000',
  initUnit: 'mi',
  returnNum: 0.32187,
  returnUnit: 'km',
  string: '0.20000 miles converts to 0.32187 kilometers'
}

So, in your getNum fraction handling, you are returning a string instead of a float and it is getting returned in the initNum property as a string. Looks like your regular expressions are not exactly what you intend.

At least on the version I just ported. I’m not seeing the error you posted; the browser console is indicating that '0.20000' is not a number.

Thanks for the reply! I forgot to convert the result to float. But the 10th test still wouldn’t pass for me. I checked the console and this is the error:

Error: expected 1.5 to be close to 1.111111111111111 +/- 0.001

It’s the same problem and same solution. Logging yields

req.query: {"input":"3/2.7km"}
{
  initNum: 1.5,
  initUnit: 'km',
  returnNum: 0.93206,
  returnUnit: 'mi',
  string: '1.5 kilometers converts to 0.93206 miles'
}

The code is picking up the 3/2 and converting it to 1.5 (initNum; as opposed to 3 divided by 2.7) and converting that to miles.

1 Like

Thank you so much! The problem was the regex because it didn’t match the . character in the getNum function

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