Learn Recursion by Building a Decimal to Binary Converter step 12

stuck on Update the second condition in your if statement to use the isNaN() function to check if the value returned by parseInt() is NaN .

got the first part of the question done by wrapping the parseInt() in the isNaN() but there is a second part that is stumping me:

You should wrap the value returned by parseInt() in the isNaN() function. And add a third condition which checks the value returned by parseInt() to be less than 0.

tried several solutions but they only focus on the wrapping element which i’ve done not the third condition.

1 Like

Please post your actual code and a link to the Step

if (!numberInput.value || isNaN(parseInt(numberInput.value))) {

}

The hint for this step says:

You should wrap the value returned by parseInt() in the isNaN() function. And add a third condition which checks the value returned by parseInt() to be less than 0.

But in your attempt you only have 2 conditions?
(i understand that your attempts are not passing but we need to see your best attempt at this. That means, try to add that third condition to the best of your ability and understanding and show us that code)

I don’t currently have code in the box but I have tried variation of things like parseInt( < 0), parseInt(numberInput.value <0), parseInt(numberInput.value <= 0) and the like but nothing worked so I am stumped and all the videos and forums only reference the second condition not the third.

can you write out the whole line of code with your best attempt at this and post it in your reply? I just want to see what you’re thinking and the only way to see that is to see your code.

my best guess would be something like:

if (!numberInput.value || isNaN(parseInt(numberInput.value)) || parseInt(numberInput.value <= 0)) {

}

okay now I see the issue.

ask yourself something, what does the method parseInt take as an input (an argument) and are you giving it what it is expecting?

honestly i don’t know i’ve needed a lot of outside help with java compared to HTML and CSS but i can’t find anything that explains it well enough for me to understand the issue

not to needlessly correct you, but you are learning JavaScript right now, not Java.

To answer the question: what does the method parseInt take as an input, you have 2 choices.
1- look at previous steps and use some logic to figure out what type of value parseInt takes.
2- google it like this “MDN parseInt” and read the documentation.

Try now and let me know what you have concluded.

ok so i checked my existing code and this is the first time using parseInt() so there is no previous example and the explanation in site and google made no sense whatsoever

how about checking step 11?

Try to read slower. You want to develop your ability to read documentation in MDN and that will take some patience on your end.

i got step 11 easy but this is confusing - i am going to start the unit over since im only at step 12 and try to wrap my head around this - i will come back if i still don’t get it

what is the argument of this parseInt?

got it I was putting the < 0 in the wrong place - a web master friend of mine explained it to me

unfortunately that friend may have prevented you from figuring this one out on your own.
Understanding how functions work is a basic skill that you will need.