logo CodeStepByStep logo

printBinary

Language/Type: JavaScript recursion

Write a recursive function named printBinary that accepts an integer as a parameter and outputs to the console that number's representation in binary (base 2). For example, the call of printBinary(43) should output 101011 to the console.

If the integer is negative, output the binary representation preceded by a minus sign. For example, the call of printBinary(-6) should output -110 .

Use console.log() to output your result to the console (on a single line).

Function: Write a JavaScript function as described, not a complete program.

You must log in before you can solve this problem.

Log In

Need help?

Stuck on an exercise? Contact your TA or instructor.

If something seems wrong with our site, please

Is there a problem? Contact us.