Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

94
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda