Learn Recursion by Building a Decimal to Binary Converter Step 69

However, remember that the binary number string is built by calculating the remainder of input divided by 2 and concatenating that to the end.

After your call to decimalToBinary(), use the addition operator (+) to concatenate the remainder of input divided by 2 to the end of the string your recursive function returns. Also, wrap the operation in parentheses.

My code is:

return decimalToBinary(Math.floor(input / 2) +'' + (input % 2));

Please explain.

1 Like

Welcome to the forum @Addel-Ali
return decimalToBinary(Math.floor(input / 2) +‘’ + (input % 2));

For a start, the concatenation and quote mark is not needed.
Second, the Math.floor is rounding down the rest of the expression.

Is this what you are trying to achieve?

Happy coding

Teller, Thank you for your reply. Still have a problem even after removing quotation mark and second concatination. I just added concatination mark (+) with input modul of 2. still not working.

use the addition operator (+ ) to concatenate the remainder of input divided by 2 to the end of the string your recursive function returns.

It should be on the function return value and not part of the arguments. So after the function call and not passed to the function call.

1 Like

lasjorg, Thanks for your help, it works now.

1 Like

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