I am extremely new to programming and have ran into a slight problem.
I am trying to convert any base 10 number to a base 2 number using JavaScript. In my code I am using "intDividend" to represent any integer between 1 and 1024 that the user inputs into the equation.
I believe I need to use a while loop instead of a for loop, however when I typed everything out, I was not able to get any answer to pop up into the text box I created on my webpage.
I can't figure out what is wrong and nothing I research seems to lead me in the right direction. This is the code that I have come up with.
function Base10ToBase2(intDividend) {
var fltQuotient=1.0
var intQuotient=1
var intRem=0
var fltDiff=0.0
var strB2=" "
while (intDividend != 0) {
fltQuotient=intDividend/2
intQuotient=parseInt(fltQuotient)
fltDiff=fltQuotient-intQuotient
if (fltDiff == 0) {
intRem=0
}
else {
intRem = 1
}
strB2 = intRem + strB2
intDividend=intQuotient
}
ConvertForm.BaseOutput.value=strB2;
}