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
res.json({
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"}