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

229
Views
Cómo hacer que el contador comience desde 0 nuevamente en JavaScript

Está bien. Estoy probando una función que cuenta números al hacer clic. Hay 2 botones; el que cuenta y el que guarda el número. Cuando se hace clic en el último, el primero debería comenzar a contar desde 0, pero mi código comienza desde el número actual

 let count = 1; function increment() { console.log("The button was clicked"); document.getElementById("count-el").innerText = count; count += 1; } function save() { document.getElementById("save-btn").innerText = count - 1; document.getElementById("count-el").innerText = 0; }
 body { margin: -2px 0 0 0; zoom: .8; } h1, h2 { margin: 0; }
 <h1>People entered</h1> <h2 id="count-el">0</h2> <button id="increment-btn" onclick="increment()">INCREMENT</button> <button id="save-btn" onclick="save()">SAVE</button>

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

0

Entonces, en la función de guardar, simplemente actualice el "let" que nombró "count"

 function save() { document.getElementById("save-btn").innerText = count - 1; document.getElementById("count-el").innerText = 0; count = 1; }
about 4 years ago · Juan Pablo Isaza Report

0

Cuando guarde datos, simplemente actualice su variable de conteo.

 let count = 1; function increment() { console.log("The button was clicked"); document.getElementById("count-el").innerText = count; count += 1; } function save() { document.getElementById("save-btn").innerText = count - 1; document.getElementById("count-el").innerText = 0; count = 1; }
 <h1>People entered</h1> <h2 id="count-el">0</h2> <button id="increment-btn" onclick="increment()">INCREMENT</button> <button id="save-btn" onclick="save()">SAVE</button>

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!