Tell us what’s happening:
Once again, the app works, and all unit and functional tests pass, but the following tests fail when I submit my link:
I can convert 'gal'
to 'L'
and vice versa. (1 gal to 3.78541 L)
I can convert 'lbs'
to 'kg'
and vice versa. (1 lbs to 0.453592 kg)
I can convert 'mi'
to 'km'
and vice versa. (1 mi to 1.60934 km)
If my unit of measurement is invalid, returned will be 'invalid unit'
.
So I compared my app’s responses to those of the example project:
“I can convert ‘gal’ to ‘L’ and vice versa. (1 gal to 3.78541 L)”
example: {“initNum”:1,“initUnit”:“gal”,“returnNum”:3.78541,“returnUnit”:“l”,“string”:“1 gallons converts to 3.78541 liters”}
mine: {“initNum”:1,“initUnit”:“gal”,“returnNum”:3.78541,“returnUnit”:“l”,“string”:“1 gallons converts to 3.78541 liters”}
example: {“initNum”:3.78541,“initUnit”:“l”,“returnNum”:1,“returnUnit”:“gal”,“string”:“3.78541 liters converts to 1 gallons”}
mine: {“initNum”:3.78541,“initUnit”:“l”,“returnNum”:1,“returnUnit”:“gal”,“string”:“3.78541 liters converts to 1 gallons”}
I can convert ‘lbs’ to ‘kg’ and vice versa. (1 lbs to 0.453592 kg)
example: {“initNum”:1,“initUnit”:“lbs”,“returnNum”:0.45359,“returnUnit”:“kg”,“string”:“1 pounds converts to 0.45359 kilograms”}
mine: {“initNum”:1,“initUnit”:“lbs”,“returnNum”:0.453592,“returnUnit”:“kg”,“string”:“1 pounds converts to 0.453592 kilograms”}
{“initNum”:0.45359,“initUnit”:“kg”,“returnNum”:1,“returnUnit”:“lbs”,“string”:“0.45359 kilograms converts to 1 pounds”}
{“initNum”:0.453592,“initUnit”:“kg”,“returnNum”:1,“returnUnit”:“lbs”,“string”:“0.453592 kilograms converts to 1 pounds”}
“I can convert ‘mi’ to ‘km’ and vice versa. (1 mi to 1.60934 km)”
{“initNum”:1,“initUnit”:“mi”,“returnNum”:1.60934,“returnUnit”:“km”,“string”:“1 miles converts to 1.60934 kilometers”}
{“initNum”:1,“initUnit”:“mi”,“returnNum”:1.60934,“returnUnit”:“km”,“string”:“1 miles converts to 1.60934 kilometers”}
{“initNum”:1.60934,“initUnit”:“km”,“returnNum”:1,“returnUnit”:“mi”,“string”:“1.60934 kilometers converts to 1 miles”}
{“initNum”:1.60934,“initUnit”:“km”,“returnNum”:1,“returnUnit”:“mi”,“string”:“1.60934 kilometers converts to 1 miles”}
“If my unit of measurement is invalid, returned will be ‘invalid unit’.”
{“error”:“invalid unit”} // example
{“error”:“invalid unit”} // mine
The only difference is that the example will truncate or round the input to 5 decimal places if it is longer. I also compared response status codes, and mine are identical to the example: 200, or 400 for bad input.
Interestingly, the tests: “If my number is invalid, returned with will ‘invalid number’.” and
“If both are invalid, return will be ‘invalid number and unit’.” both pass for me. I checked to make sure there isn’t a spelling error in {“error”:“invalid unit”}. There isn’t. Also when I paste in the link for the example app, it also fails this test! Yet it somehow passes the conversion tests, even though in most cases my app’s response bodies are character-for-character identical, and when they’re not, it’s because of a difference of like 0.000002.
Once again, either there is a problem with the tests, or the user stories aren’t clearly explaining the actual requirements. It seems like I need to be able to debug the FCC test code to figure out what the problem is. It’s getting a bit frustrating!
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/86.0.4240.111 Safari/537.36
.
Challenge: Metric-Imperial Converter
Link to the challenge: