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