0
I am trying to make a limiter so that every time the user type a number that is not binary, receive an alert with the message "Write a binary number" however the problem is that the code sends the message, but continues running the function
function Bin2Dec ()
{
const numeros = document.getElementById("char-input").value;
if (numeros === '')
{
return alert("Por favor, escreva um numero binário");
}
numeros.split('').map((char) => {
if (char !== '0' && char !== '1') return alert("Por favor, escreva um numero binário");
});
const decimal = parseInt( numeros, 2 );
document.getElementById("convertido").innerHTML = numeros + " na base decimal é: " + decimal;
}
For those who want to see the site https://sancheesandre.github.io/Bin2Dec/
– SancheesDev