Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9194087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T21:19:19+00:00 2026-06-17T21:19:19+00:00

I am looking to write a script which: Constantly changes the background color every

  • 0

I am looking to write a script which:

  1. Constantly changes the background color every 1 second.
  2. When you first access the webpage the starting color is set based on the time of day. So if I access the website at: 7am (or close to that time) everyday it will always be a share of red no matter if I have had my browser open for 10hours.

How could I do this without loads of IF statements?

Looking here: https://stackoverflow.com/a/1455177/560287 it says there are 16776960 different colors, I dont need that many but how could I reduce this into a setInterval so it fades through the colors of a rainbow every second?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T21:19:20+00:00Added an answer on June 17, 2026 at 9:19 pm

    This works:

    First lets make the function that will do it:

        "use strict";
                function changeColor() {
        //rgb
        console.log('event fired');
        var colors = [0, 0, 0];
        var hour = new Date().getHours();
        console.log(hour);
    
        //Will get an valid rgb color
        var color = parseInt(255/24*hour);
        console.log(color);
        for(var i = 0; i < colors.length; i++) {
            colors[i] = color;
        }
        //add the color to the element you want:
        document.body.style.backgroundColor = "rgb("+colors[0] + "," + colors[1] + "," + colors[2] + ")";
        console.log("event fired. color get:" + colors[0] + colors[1] + colors[2]);
      }
    

    After, let’s make a event that will be fired in each 30 minutes(the color will be changed every 30 minutes):

    setInterval(changeColor,1800000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm looking to write a Ruby script which I can load into the Rails
Not sure this is possible, but looking to write a script that would return
I'm looking to write a Java program which will download a Java source file
I am looking to write application for iPhone which will be able to control
I am trying to write a script which will automate a copy/paste of employee
I am new to python and try to write a script which makes byte
I'm looking to write a PHP script to act as a mini daemon to
I'm looking to write HTML tables, which contain PHP variables inside the columns, to
I want to write a bash script which will use a list of all
I am looking for some examples/advice on how to write a Perl script to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.