Tell us what’s happening:
This is my code for covert base10 to base2
But it show error “Your decimalToBinary function should return “1010” as a string.” I write log and it show 1010 already
const decimalToBinary = (input) => {
let quotient = input;
let result = “”;
while (quotient > 0) {
let remainder = quotient % 2;
result = remainder.toString() + result;
quotient = Math.floor(quotient / 2)
return result.padStart(4, "0");
};
Your code so far
<!-- file: index.html -->
/* file: styles.css */
/* file: script.js */
// User Editable Region
let quotient = input;
// User Editable Region
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Safari/537.36
Challenge Information:
Learn Recursion by Building a Decimal to Binary Converter - Step 19