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

Tell us what’s happening:

The task is to remove console.log() statement and call the decimalToBinary with the value of numberInput.value like this

decimalToBinary(parseInt(numberInput.value)).

But it keeps failing by showing -

  1. You should remove the console.log() statement from your checkUserInput function.

Your code so far

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

const decimalToBinary = (input) => {

};

const checkUserInput = () => {
  if (
    !numberInput.value ||
    isNaN(parseInt(numberInput.value)) ||
    parseInt(numberInput.value) < 0
  ) {
    alert("Please provide a decimal number greater than or equal to 0");
    return;
  }


// User Editable Region

 decimalToBinary(parseInt(numberInput.value));
};

// User Editable Region


convertBtn.addEventListener("click", checkUserInput);

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

Your browser information:

User Agent is: Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36

Challenge Information:

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

Your code works for me. Try to click reset and then try it again, maybe it will work. If not, I would move on.

1 Like