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