Learn Recursion by Building a Decimal to Binary Converter - Step 73

Tell us what’s happening:

Anyone know what am I exactly doing wrong here? The output states
If input is equal to 0 or 1 , your decimalToBinary() function should return String(input) .

/* file: script.js */
const numberInput = document.getElementById("number-input");
const convertBtn = document.getElementById("convert-btn");
const result = document.getElementById("result");

const decimalToBinary = (input) => {

// User Editable Region

  if (input === 0 || input === 1 ) {
   return decimalToBinaryString(String(input));

  } else {
    return decimalToBinary(Math.floor(input / 2)) + (input % 2);
  }

// User Editable Region

};

const checkUserInput = () => {
  if (!numberInput.value || isNaN(parseInt(numberInput.value))) {
    alert("Please provide a decimal number");
    return;
  }

  result.textContent = decimalToBinary(parseInt(numberInput.value));
  numberInput.value = "";
};

convertBtn.addEventListener("click", checkUserInput);

numberInput.addEventListener("keydown", (e) => {
  if (e.key === "Enter") {
    checkUserInput();
  }
});

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36

Challenge Information:

Learn Recursion by Building a Decimal to Binary Converter - Step 73

Hello!

You just have to return the stringified “input”, no need for a function .