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

246
Views
Javascript, alerta cuando el valor es cero

Estoy diseñando un juego.

Hay un punto de vida, id llamado 'punto de vida'.

Además, hay una función: haga clic con el mouse para disminuir el valor de 'punto de vida'.

Quiero tener una nueva función:

Alerta cuando el punto de vida <= 0, mi función de alerta no funciona.

 function decrementlife() { var element = document.getElementById('lifepoint'); var value = element.innerHTML; --value; console.log(value); document.getElementById('lifepoint').innerHTML = value; } $(function (){ var value = $('lifepoint').val(); if( value == '0' ) { alert('GG') } })
about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

¿Por qué no poner directamente dentro de la función decrementlife ?

 function decrementlife() { var element = document.getElementById('lifepoint'); var value = parseInt(element.innerHTML);// it's a string with innerHTML so convert to int --value; if(value <= 0) { alert("Boom!!")} // alert it here console.log(value); document.getElementById('lifepoint').innerHTML = value; }

about 4 years ago · Santiago Trujillo Report

0

Se llama a $(function (){}) una vez que todos los elementos DOM de la página están listos para usarse.

su debe llamar alert directamente en decrementlife

about 4 years ago · Santiago Trujillo 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!