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

140
Views
How to execute a function only when its called on. JAVASCRIPT

const START_BTN = document.getElementById("start")
const TEXT = document.getElementById("top")
let TIMER = document.getElementById("time")

START_BTN.addEventListener("click", start)
TIMER.innerText = "30"

let TIMER_FUNC = setInterval(countdown, 1000);


function start(){
    START_BTN.style.display = "none"
    TEXT.style.display = "block"

    countdown()
}

function countdown(){
    TIMER.innerText--
}
    <div class="game">
        <button id="start">Start</button>
        <div id="top">
            <div class="color1">RED</div>
            <div class="color2">YELLOW</div>
        </div>
        <div class="bottom">
            <div class="row1">
                <button class="blue"></button>
                <button class="yellow"></button>
            </div>
            <div class="row2">
                <button class="green"></button>
                <button class="red"></button>
            </div>
        </div>
    </div>
    <div class="span">
        <span id="score"></span>
        <span id="time"></span>
    </div>

Basically, I want the countdown which is the timer to only start when the start function is active. The start function is a button and when clicked I want the timer to go down. Currently its going down on window load which makes sense but its not what I want.

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!