Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

99
Vistas
Paint numbers with Javascript

I didn't find anything related on the internet.

I need a javascript code that returns me the green or red color according to the number.

But I don't want it to be static, for example the more negative the redder it gets. And the more positive, the greener it gets.

-1 and 1 would have light colors for example, 1000 and -1000 would be stronger. Similar to what is done in excel and Google Spreadsheet.

this is what i tried with the negative numbers:

detail: I don't want 255 to be the maximum or minimum

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Test</title>
</head>
<body>
    <div id="number">
        -100
    </div>
</body>
<script>
    var div = document.querySelector('#number');
    var number = Number(document.querySelector('#number').innerText);
    var redRgb = 255;
    console.dir(redRgb + number);
    div.style.color = `rgb(${redRgb + number},0,0)`;
</script>
</html>

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda