Metric-Imperial Converter "invalid number" test error

I finished my project and it works, but I can’t pass the “invalid number” and “invalid number and unit” tests, even if they work on the site. can you help me?

Your project link(s)

Challenge: Metric-Imperial Converter

Link to the challenge:

I think this is one of issues specific to Glitch, some more information in the post and thread linked below.

Hey, gives error , try to fix this

I think there is something in this piece of code that doesn’t work. Can you help me?

let inputRegex = /[a-z]+|[^a-z]+/gi;

function ConvertHandler() {
this.getNum = function(input) {
let result;
result = input.match(inputRegex)[0];
let numRegex = /\d/;
if (numRegex.test(result) === false) {
result = 1;

if (result.toString().includes("/")) {
  let values = result.toString().split("/");
  if (values.length != 2) {
    return "invalid number";
  values[0] = parseFloat(values[0]);
  values[1] = parseFloat(values[1]);
  result = parseFloat((values[0] / values[1]).toFixed(5));

if (isNaN(result)) {
  return "invalid number";

return result;


On Replit all test fails with this code

Honestly I’m kinda impressed with your code, well done!
what if server would just respond with “invalid number and unit” if there’s no input? lazy approach yep. but everything else seems to work fine

upd. without trying to convert anything

Could you link to the code on replit? One thing that needs to be changed is using the Secrets tab on replit for environmental variables, instead of the .env file. Other than that I don’t think running it on replit would require code changes.

After adding required NODE_ENV environment variable with value true, in the Secrets tab, all tests passed for me on the fork of your code.


Thank you all. I tried my code on replit and it worked

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