Metric-Imperial Converter json value needs to be fixed

so the unit and functional tests are passing but i get errors when trying to submit my code for freecodecamp, after some research i found that the values need to be fixed to 5 decimal values and i managed to do that for the string but it’s not working for the json respnose output. here are the related snippets of code:

  // Function to generate the output string
  this.getString = function(initNum, initUnit, returnNum, returnUnit) {
    const spellOutInitUnit = this.spellOutUnit(initUnit);
    const spellOutReturnUnit = this.spellOutUnit(returnUnit);
    let result = `${initNum} ${spellOutInitUnit} converts to ${parseFloat(returnNum.toFixed(5))} ${spellOutReturnUnit}`;
    return result;
    // Send the response
      initNum: initNum,
      initUnit: initUnit,
      returnNum: parseFloat(returnNum.toFixed(5)),
      returnUnit: returnUnit,
      string: string

Output when I try converting “1 lbs”:
1 pounds converts to 0.45359 kilograms

{"initNum":1,"initUnit":"lbs","returnNum":0.453592,"returnUnit":"kg","string":"1 pounds converts to 0.45359 kilograms"}

Post a repo with your code.

It looks like it is the “vice versa” part of the three tests that are failing.

E.g. ‘gal’ to ‘L’ returns the correct value, ‘L’ to ‘gal’ does not.

Open the browser network tab and inspect the request/response when you submit.

that’s the network tab when submitting, i don’t see anything unusual


Filter for Fetch/XHR and submit. Now click on the responses.



Responds with:

  "initNum": 10,
  "initUnit": "L",
  "returnNum": 2.6417217685798895,
  "returnUnit": "gal",
  "string": "10 liters converts to 2.64172 gallons"

that’s what i see

i made the convert function in convertHandler.js fixed to 5 deicmal points and it worked