Quality Assurance Projects - Metric-Imperial Converter

Tell us what’s happening:
I’m able to pass all the conversion tests except the lbs to kg and vice versa test. I’ve gone through my code several times now and cant catch the mistake.
Please help me find the mistake.

Thanks in advance!

Your project link(s)

solution: boilerplate-project-metricimpconverter - Replit

Your browser information:

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

Challenge: Quality Assurance Projects - Metric-Imperial Converter

Link to the challenge:

I think this test might be broken because its looking for 6 sig figs in the output but the instructions tell you to keep the output to 5 sig figs. If any moderators see this please help. I’ve been stuck at this for way to long and I dont think it’s a me issue.

If it was a problem with the tests the example project wouldn’t be passing.


It looks like you are missing a digit

Response

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

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


You need to update your Replit link BTW.

updated link: https://metricimperialconverter.mmuneeb.repl.co

yes, because I’m round to 5 decimal places as stated in the instructions and all other conversion tests pass, just this one that doesn’t pass

This isn’t returning the correct thing

https://metricimperialconverter.mmuneeb.repl.co/api/convert?input=1kg

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

And this request https://metricimperialconverter.mmuneeb.repl.co/api/convert?input=10kg never happens, didn’t look at the code so not sure why.


Im not sure what you mean. I get this for 1lbs. which matches the test:

but it still doesn’t pass

https://www.google.com/search?q=1kg+to+lbs


Here is the tests in case you are curious

https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/06-quality-assurance/quality-assurance-projects/metric-imperial-converter.md

async getUserInput => {
  try {
    const data1 = await $.get(getUserInput('url') + '/api/convert?input=1lbs');
    assert.equal(data1.returnNum, 0.45359);
    assert.equal(data1.returnUnit, 'kg');
    const data2 = await $.get(getUserInput('url') + '/api/convert?input=10lbs');
    assert.equal(data2.returnNum, 4.53592);
    assert.equal(data2.returnUnit, 'kg');
    const data3 = await $.get(getUserInput('url') + '/api/convert?input=1kg');
    assert.equal(data3.returnNum, 2.20462);
    assert.equal(data3.returnUnit, 'lbs');
    const data4 = await $.get(getUserInput('url') + '/api/convert?input=10kg');
    assert.equal(data4.returnNum, 22.04624);
    assert.equal(data4.returnUnit, 'lbs');
  } catch (xhr) {
    throw new Error(xhr.responseText || xhr.message);
  }
};

That helps a lot. thanks! seems like my conversion factor is off.

[SOLVED]: I was missing a break after my kg case in the switch statement

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