Codecademy Forums

Zeros to String type

Hi dear colleagues!

My program must get numbers from 0 to 9. It can be 00000 for example.
Then I need to convert numbers to string for futher iteration.
And I faced with a problem.

I did a little checker. If I get integer type from user, I will convert it to strings.
But it doesn’t work with 00000 numbers. 0000 becomes only one Zero. I need all zeros in my code.
Please give me a hint)

const checkCode = code => {
  if (typeof code === 'number') {
    code = code.toString();
    return code;
  }  else if (typeof code === 'string') {
    return code;
  } else {
    return 'Input is incorrect!';
  }
}

console.log(checkCode(000000)); // Returns 0

Hey @beta5773653430! Can you send us the link to the exercise?

But the reason it might be doing this is because 00000 = 0 so it automatically converts into one zero.

1 Like

What can I do with it?)

I don’t have exercise right now, a little bit later. But meaning is - to find all combinations of pin code. And I must work with strings, because answer can be 000000 for example.

So why not make it so you must input a string? If this isn’t an exercise then you have full rein over the way the function is called and what it is called with. Basically what I’m trying to say is why does it have to be a number? Or actually, does it have to be a number?

To be honest, I don’t think it is possible to define a variable and make it equal to a sequence of zeroes.

I’m also not exactly sure what the purpose of this code is; can you please explain in more detail what you are trying to do?

3 Likes