Metric-Imperial Converter

The following test is not passing

You can use fractions, decimals or both in the parameter (ie. 5, 1/2, 2.5/6), but if nothing is provided it will default to 1.

The error looks to be - [Error: expected undefined to be a number]

im using the following to split the numbers from the string

let nums = "0123456789";

 //check if string digit is a number
    function checkNum(x) {
      return nums.includes(x) ? true : false;
    }

    // combine number digits
    let numbers = [...input].reduce(
      (x, y) => (checkNum(y) ? x + y : x),"");

I use the condition to check to return 1 if no number is provided

   if (!numbers) {
      return 1;
    }

I am not sure what I’m missing I have been looking to see where in the code undefined is coming up for the Initial number

Your project link(s)
convertHandler.js - boilerplate-project-metricimpconverter - Gitpod Code

Your browser information:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36 Edg/128.0.0.0

Challenge: Quality Assurance Projects - Metric-Imperial Converter

Hello, you have a function that appears to be closed with more code. Is this how you wrote this? Note: I was unable to use the link through Git Hub login.
Workspace freecodecam-boilerplate-fw45jrg1kap not found.

You can use typeof to check the data type.

includes already returns true or false so you do not need a ternary.

Also, if you use the array version and give it an array of numbers it won’t convert a string input, as opposed to using the string version.

console.log("12".includes(1)); // true
console.log([1, 2].includes("1")); // false

As said, we can’t see your code. If you need more help, share a snapshot of your Gitpod workspace or post a GitHub repo.

https://gitpod.io#snapshot/a87b345d-34e2-432c-8769-8936648308f0

I have a snapshot here. I just copied the parts of the code where I as trying to return a 1 as default.

https://gitpod.io#snapshot/a87b345d-34e2-432c-8769-8936648308f0

I have the snapshot here. thanks for the help

You are trying this make this test pass, correct?

You can use fractions, decimals or both in the parameter (ie. 5, 1/2, 2.5/6), but if nothing is provided it will default to 1.

I would suggest you log out the various values you have before the first if statement.

input >> 1/2km
numbers >> 12
unit >> [ 'km' ]
input.length >> 5
unit[unit.length - 1].length >> 2
input.length - unit[unit.length - 1].length >> 3
numbers.length < (input.length - unit[unit.length - 1].length >> true
IF CONDITION TRUE

Thanks, it does pass now