Build a decimal to binary converter

const numberInput = document.getElementById("number-input");
const convertBtn = document.getElementById("convert-btn");
const result = document.getElementById("result");

const decimalToBinary = (input) => {
  const inputs = [];
  const quotients = [];
  const remainders = [];

  while (input > 0) {
    const quotient = Math.floor(input / 2);
    const remainder = input % 2;

    inputs.push(input);
    quotients.push(quotient);
    remainders.push(remainder);
    input = quotient;
  }

console.log(`Inputs: ,${inputs}`)

};

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;
  }

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

convertBtn.addEventListener("click", checkUserInput);

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


Step 31

Now’s a good time to check your work.

Log the text "Inputs: ", followed by a comma, followed by the inputs array to the console.

step 31 not passing for some reason

You need to post the link to the challenge or project, was there HTML and CSS?

Hey. purely a javascript project. I posted the challenge number, ill get the link

1 Like

Read the console out put and pay attention to the grey highlighted words, It simpler than you think.

console.log(Inputs: ,${inputs})
not sure why this doesn’t work.
for some reason my backticks arent showing in my post

It is just a string + a comma + the array variable. No need for the string literal etc…

weird, i tried that and it didn’t pass

Refresh your browser or reset the challenge, that usually works.

1 Like

did you get it to pass? I tried the refresh and reset, still not passing

console.log("Inputs: " + ‘,’ + inputs)
console.log(“Inputs: ,”+ inputs)

With out giving the full answer you would have (" " , var) so you are very close.

1 Like

thanks that worked. Not sure why mine didnt’ work