Getting an error for an implemented method that works (recreating the Lodash library)

Hello everyone,
i get an error (RangeError: Invalic count value at String.repeat (navite)…) when I test the pad() method using node.
When I test it on different places, (for instance on DevTools) it works perfecly.
Am I missing something?
That’s the link to my code:


And that’s the link to the exercise:
https://www.codecademy.com/paths/web-development/tracks/web-dev-js-arrays-loops-objects/modules/pjs-javascript-capstone/projects/lodash
Thanks

What do you mean by test, and does it mean the same thing when you do it in your browser as it means when you do it in node?
If you have a failing test then it wouldn’t make sense to do other tests, you’d want to use the failing test. And if you have a failing test then you also have information about what input your function doesn’t handle, the input that the test provided.

By testing I mean that if i run the _.pad() I’ve designed with different ‘string’ and ‘length’ values the result is always correct while when i run it in node it gives me an error.
The point is I don’t understand why it gives me an error.

I bet if you run it the same way on node it’ll “work” there too.

The difference is that you’re not calling it the same way in both places.

If you have input X which fails
And inputs ABCDEFG that all succeed.

Then getting ABCDEFG to run in a different environment doesn’t prove that it’s the environment that is the problem. You should run X. You’re avoiding running the failing input.

Another way to not fail is to not call the function, then it will be correct for all input, because there aren’t any inputs.

I wasn’t saying the environment is the problem.
I was just asking what was wrong with my code.

You were saying there’s a difference. But you’re not doing an equivalent thing on both, so you’re not showing that there is a difference, and there probably isn’t.

Your test says what’s wrong. Doesn’t handle that input.

You might expect the test to show the input in red text since it’s showing passes in green text.
But…those tests aren’t particularly thorough or … anything in that direction.
However, they still do provide the information you need, you’re still able to read the test to see what the next test is, or print out what the input is from your function.

But an important part is also in realizing that, hey, my code crashed during testing… I want to know what the input was.

As I said I can see the error RangeError: Invalid count value at String.repeat (navite)…
I just wanted to know what was wrong in my code since this error is shown.
I reckon that is caused by the .repeat() but if I could have had figured the solution out I wouldn’t have asked it here in the very first place.

Yeah, so, what value did you use that was invalid?

You have this information.

Ok, I found the issue.
The var newWord was defined before my if statements and the function couldn’t handle the input (padding) when it was negative.
String.repeat(negative value) couldn’t be handled.
I moved newWord inside my if statement and it’s applied only when padding is a positive value.
I do need to practice more in understanding the errors.
Thanks for your help!

1 Like

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