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

181
Views
Cambiar el color del texto según la variable

Intentando hacer un simple contador de aumento/disminución. Cuando var n es <0, cambia a rojo, y lo mismo para ==, pero cuando es mayor que permanece negro... ¿me estoy perdiendo algo?

 var n = 0 function increase() { n = n + 1 document.getElementById('num').innerHTML = n if (n > 0) { document.getElementById('num').style.color = '#013220' } else if (n < 0) { document.getElementById('num').style.color = '#ff0000' } else if (n == 0) { document.getElementById('num').style.color = '#000000' } }

sin mensajes de error.

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

0

esta es una manera de hacerlo:

 var n = -2. // let me start with a negative number so we can see that color too function increase() { n = n + 1; let color = '#000000'; // default color is black if (n > 0){ color = '#CC0'; // yellow when n > 0 } if (n < 0){ color = '#ff0000'; // red when n < 0 } const elem = document.getElementById('numWrapper') elem.innerHTML = n elem.style.color = color }
 <div id='numWrapper'>-2</div> <button onClick='increase()'>Increase</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!