Во-первых, вы пытаетесь оценить элементы, а не их ценность. Кроме того, у вас много ненужных условных выражений. Мы также хотим реструктурировать то, как мы храним наши учетные данные, чтобы сделать его более интуитивно понятным.
function login() {
// Instead of storing usernames and passwords in separate arrays,
// we instead will store them as an array of objects with username
// and password properties
var logins = [
{ username: 'user1', password: '1' },
{ username: 'user2', password: '2' },
{ username: 'user3', password: '3' }
];
// Get the values of our inputs
var idInput = document.getElementById("id").value;
var pwInput = document.getElementById("pw").value;
// The find method on array returns the first occurrence in the
// array if the condition evaluates to true. In this case, we
// need to make sure the username and password match what was
// entered. The !== undefined determines whether or not find
// returned a match that met the search criteria.
const success = logins.find(login => login.username == idInput && login.password == pwInput) !== undefined;
// If it found a match, then we alert the appropriate response.
if(success) {
alert('Successful login!');
} else {
alert('Failed login!');
}
}
<table>
<tr>
<td>Login Id:</td>
<th>
<INPUT type="text" Size="40" Maxlength="35" id="id" placeholder="Your Username Here">
</th>
</tr>
<tr>
<td>Password:</td>
<th>
<INPUT type="text" Size="40" Maxlength="40" id="pw" placeholder="Your Password Here">
</th>
</tr>
</table>
<button onclick="login()">Login</button>