Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

241
Views
I want to alert a value when I press the Esc button in prompt, but I have no idea... (code below)

const login = prompt("Enter username!", "");

if (login === "Admin") {
  prompt("Enter password!");
} else if (login === "" || login.keyCode === 27) {
  alert("Canceled");
} else {
  alert("I don't know you!");
}

This is the error message when I press Esc:

'Cannot read properties of null (reading 'keyCode') at logical-operators.html:77'

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

when you press ESC the login value will become null so you can check like this:

if(!login){
  alert('cancled')
}

or you can add listener to dom if ESC clicked :

document.addEventListener("keyup", (e) => {
    if (e.key === "Escape") {
      // escape key maps to keycode `27`
      alert('cancled')
    }
  });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!