Answer the question
In order to leave comments, you need to log in
Why does not see the second array object?
Hello. There is a task:
Write a simple authorization program. Create an array users, in which each element is an object of type "user" with the properties "name", "login" and "password". The program should prompt the user for a login and password using prompt, and then go through the users array and look for an object with the same values in it. If the user is found in the users array, then the program should greet him by name. Otherwise, an authorization error should appear.
let authorization = [
{
username: 'Ruslan',
login: 'Lorelin',
password: '12345'
},
{
username: 'Margarita',
login: 'ririka',
password: '54321'
}
];
let login = prompt('Введите логин');
let password = prompt('Введите пароль');
let user = null;
for (let i = 0; authorization.length; i++) {
if (authorization[i].login == login && authorization[i].password == password) {
user = authorization[i];
alert('Привет, ' + user.username);
break;
}
else {
alert('Логин или пароль не верен.');
break;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question