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

88
Views
Loading indicator in promises - JS

When i click the button to login, paragraph does not render in the screen. It looks like that changing the style of an element via JS is an async task.

const p = document.getElementById("loadingIndicator");
const btn = document.getElementById("loginBtn");

btn.addEventListener("click", () => {
    p.style.display = "block"; //is this async ?
    new Promise((resolve, reject) => {
        const username = prompt("Enter username: ", "");
        const pass = prompt("Enter password: ", "");
        
        if(
            username.toLowerCase() == "mora" &&
            pass.toLowerCase() == "learncode"
        ) {
            resolve("Successfully login");
        } else {
            reject(new Error("Something went wrong!"));
        }
    })
    .finally(() => p.style.display = "none") 
    .then(
        result => {
            console.log(result);
        },
        error => {
            console.warn(error.message);
        }
    );
});

How to fix this?

about 4 years ago · Juan Pablo Isaza
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!