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

93
Views
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
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!