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

163
Views
Function returning the initial value instead of the updated value

My code is supposed to update "level" to the value of "level_num" but instead, it keeps returning 0.

function find_level() {
    let level_num = 0;
    document.querySelector("#easy").onclick = () => {
        document.querySelector("h3").innerHTML = `You chose Easy. Good Luck!`
        level_num =  1;
    }

    document.querySelector("#medium").onclick = () => {
        document.querySelector("h3").innerHTML = `You chose Medium. Good Luck!`
        level_num = 2;
    }

    document.querySelector("#hard").onclick = () => {
        document.querySelector("h3").innerHTML = `You chose Hard. Good Luck!`
        level_num =  3;
    }
    return level_num;
}

document.addEventListener('DOMContentLoaded', function() {

    let level = find_level();
    document.querySelector("h1").innerHTML = `You chose ${level}. Good Luck!`
})
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!