Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 138221

JavaScript "escape condition=null" not working with "toLowerCase" method .. Code included below

$
0
0
let username = prompt('Enter the username','');

    if (username.toLowerCase()=='admin') {

        let password = prompt('Enter the password','');

        if (password.toLowerCase()=='themaster'){
            alert('Welcome!');
        } else if (password=='' || password == null) {
            alert('Cancelled');
        } else {
            alert('Wrong Password!');
        }

    } else if (username=='' || username == null) {
        alert('Canceled!');
    } else {
        alert('I don\'t know you!');
    }

Here I wish to show "Cancelled", if a person press "Escape". So I have given the condition that if a user leaves the field empty OR press escape (which returns null), it should show cancelled. But its not showing "Cancelled" in case of pressing "Escape" button. But when i remove the ".toLowerCase()" method, then it works. Can someone explain .. Why ?


Viewing all articles
Browse latest Browse all 138221

Trending Articles