I'm trying to write a script to accept at maximum 8 binary elements, verify if they are indeed binary and show they representation in decimal numbers. I'm stuck in the verification. I'm pretty new at programming and I don't know how to solve this problem.
function verify() {
var numBin = document.getElementById('bin-input')
var c = 0
if (numBin.value == "" || numBin.value.length > 8 || isNaN(numBin) == "True"){
alert('Write only 8 binary elements!')
} else (while (numBin.value.length != c){
if (numBin.length[c] == '0'|| numBin.length[c] == '1'){
c ++
} else {
break
}
}){
alert('Write only 0 and 1')
}
}
This is what I've made so far but the while inside the else if isn't working and I don't know how to fix it. How can I fix this issue?
isNaN(numBin) == "True"<-- I think you need to read the documentation for isNaN(while (numBin.value.length != c)block. Remove== "True"--isNaN(numBin)is enough to test a boolean. Other than that, what isn't working specifically? How should it work?