I am trying to make an array with names, then to iterate them using a for of loop and then to check the iteration using a if else statement. My code is below, but it did not work, I saw no result. I tried with for in, the same bad result. In Html file I have a paraghraph with demo id and a button with function for iterate and checking array
function availableName() {
const check = document.getElementById('userID');
const takenNames=['manuel','remus','manuel-remus','tomi','mirel'];
const reservedNames=['cristina','angela','rusanda','costantin'];
const givenNames=[...takenNames, ...reservedNames];
for (givenName of givenNames) {
if (givenName === check) {
sayMessage=givenName +"Not available!";
}
else {
sayMessage= givenName +"Available";
}
}
document.getElementById("available").innerHTML= sayMessage;
};
document.getElementById('userID')should bedocument.getElementById('userID').valueif userId is an inputif ( givenName === check.value ), as check is actually a dom element not the value of element itself.givenNamesis a combination of bothtakenNamesandresrevedNames.