Fill a set of five names with prompt(s)



  • Cyclom needs to fill a mass with a prompt team that will have a list of five names. Then release a prompt message requesting the use of a user name

    The name in it, the cycle compares the names in the mass. If the user ' s name does not exist in the mass, give a notice of error by alert(s). If there's a coincidence, get a message. "Andrey, you've successfully entered."

    For Andrey. the name of the current user

    I threw the code, but it's incomplete and I can't understand the algorithm of action.

    var arr = [];
    

    for (var i = 0; i < arr.length; i++);

    var a = prompt("Enter your name");

    if (a == arr) {
    alert( a + " вы успешно вошли! ");
    } else{
    alert("Ошибка")
    }



  • var arr = ['Андрей','Петр','Алексей'],
            a = prompt("Enter your name"),
        i = 0;
    while (i < arr.length) {
      if (a == arr[i]) {
        alert("Ошибка");
        return false;
      } else if(a !== arr[i] && i === (arr.length-1)){
        alert( a + " вы успешно вошли! ");
        arr.push(a);
        console.log(arr);
        return false;
      }
      i++;
    }
    

    After a successful addition, it is clear that a new user is added


Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2