lundi 26 mars 2018

Iterate and checking an array with for of loop and if..else statement

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;
 };

Aucun commentaire:

Enregistrer un commentaire