Tell us what’s happening:
I tried the method that I think is the possible solution but it is not? please can someone help me with this one???
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) => {
// User Editable Region
const tempArray = [];
for(let i = input.value; i <= 1; parseInt(i/2)){
if(i === 1){
tempArray.unshift('1');
break;
}
if(input.value%2 == 0){
tempArray.unshift('0');
}else{
tempArray.unshift('1');
}
}
return tempArray.join('');
// User Editable Region
};
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();
}
});
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36
Challenge Information:
Learn Recursion by Building a Decimal to Binary Converter - Step 19