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

Tell us what’s happening:

Describe your issue in detail here.

My Math.floor() code is not passing the challenge.

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) => {
  let binary = "";

  while (input > 0) {

// User Editable Region

    input = 0;
    input =  Math.floor( input / 2 );   

// User Editable Region

  }

  result.innerText = binary;
};

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

  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/109.0.0.0 Safari/537.36

Challenge Information:

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

You appear to have created this post without editing the template. Please edit your post to Tell us what’s happening in your own words.

Hi @edwin1

Why are you assigning zero to input?

Happy coding

Ooh! that’s the mistake.

the zero assignment to input was my previous challenge then i forgot to clean it.

1 Like

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