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

Hello,

Quick question

why in the code I need launch

decimalToBinary(inputInt) and not directly decimalToBinary()

and then why do I need the “input” in const decimalToBinary = (input) => {};

then why something like this is not working :

convertBtn.addEventListener("click", checkUserInput);

const checkUserInput = () => {
  const b = parseInt(numberInput.value);

  if (!numberInput.value || isNaN(b)) {
    alert("Please provide a decimal number");
    return;
  }

  if (b === 5) {
    showAnimation();
    return;
  }

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

const decimalToBinary = () => {
  const a = parseInt(numberInput.value)
  if (a === 0 || a === 1) {
    return String(a);
  } else {
   const c = (decimalToBinary((a / 2)) + (a % 2));
   
    return String(c);
    
  }
};

I belive I’ve miss the key information at some point :sweat_smile:
thanks

Challenge Information:

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

because the function needs a number to convert, and that is given to the function as the argument

to use the value of the arguments you need to give a parameter when you create the function

the function is missing the argument, the function doesn’t know what number to convert

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