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

199
Views
El número aparece como NaN en lugar del número en mi variable

Necesito que aparezca como "0" antes de hacer clic y, por alguna razón, aparece como NaN, ¡ayuda!

 <html> <head> <script> var money = 0; var clickingPower = 10; function moneyClick() { var clicks = clicks + 1; document.getElementById("money").innerHTML = money + clickingPower * clicks; } </script> </head> <h1>You have <span id="money"></span> dollars</h1> <button onclick="moneyClick()">Click to make money</button> </body> </html>
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

es esta linea

 var clicks = clicks + 1

Su variable de clics aún no existe, es por eso que obtiene NaN

about 4 years ago · Juan Pablo Isaza Report

0

Estás usando clicks antes de definirlo.

puedes probar esto:

 <html> <head> <script> var money = 0; var clickingPower = 10; function moneyClick() { var clicks = (clicks || 0) + 1; document.getElementById("money").innerHTML = money + clickingPower * clicks; } </script> </head> <h1>You have <span id="money"></span> dollars</h1> <button onclick="moneyClick()">Click to make money</button> </body> </html>
about 4 years ago · Juan Pablo Isaza Report

0

Tienes que inicializar la variable clicks :

 var clicks = 0; function moneyClick() { clicks = clicks + 1; document.getElementById("money").innerHTML = money + clickingPower * clicks; }
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!