New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor decimal to binary converter to check for positive numbers only #54651
Comments
hello , "Please reply to this. What output do you prefer for negative numbers?" |
@Asadali00000 What output is preferred is the question to those brilliant minds of the people who created and worked on this project in the first place. I'm still on the stage of making my brain comprehend how binaries work :) and it all thanks to this project to begin with. |
If I remember correctly, I believe the original design was to only account for positive numbers. But IMO, I think we should just add a note in the beginning for step 1 that this project will build out a binary converter for positive numbers. Because the real goal is to reach recursion and not so much of teaching an in depth lesson on binary if that makes sense. I will open this up for discussion so the rest of the team can chime in |
Thanks for bringing this to our attention, @code-liana, and for taking the time to open up this issue. As cool as it would be to update the algorithm to work with negative numbers, I agree with @jdwilkin4 that this project should focus more on recursion rather than going too much into decimal to binary conversion. Like Jessica mentioned, we could adjust the text in step 1 to emphasize that this project will only convert positive numbers into binary. And while this would involve more changes, we could adjust the first Towards the beginning of the project the if (!numberInput.value || isNaN(parseInt(numberInput.value)) || parseInt(numberInput.value) < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
} Then later after refactoring to use the if (!numberInput.value || isNaN(inputInt) || inputInt < 0) {
alert("Please provide a decimal number greater than or equal to 0");
return;
} That seems like an easier solution than adding in another |
I like that approach @scissorsneedfoodtoo Let's go ahead and open this up for contribution |
Describe the Issue
STEPS TO REPRODUCE:
RESULT:
Negative numbers are displayed as
isNaN = false
but the app displays NaN on the result field.The user can see on the console if the application running through the website of freeCodeCamp
Potential infinite loop detected on line 32. Tests may fail if this is not changed.
If I copy html, css and js file to vc and run it stand-alone on the browser I see this on the console
Affected Page
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/learn-recursion-by-building-a-decimal-to-binary-converter/step-109
Your code
Expected behavior
As far as I read on Google negative numbers can be converted to binary but it's the whole process,
Here is a clear example of how to do it at the bottom of the article: https://sciencing.com/calculate-binary-numbers-8267989.html
Screenshots
RESULT ON FREECODECAMP
RESULT WHEN COPIED TO LOCAL
System
Device: Laptop
OS: Windows 11 Home
Browser: Chrome
Version: 124.0.6367.61
Additional context
No response
The text was updated successfully, but these errors were encountered: