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 8600963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T01:44:08+00:00 2026-06-12T01:44:08+00:00

So I wanted to make every word in the text different color, but I’ve

  • 0

So I wanted to make every word in the text different color, but I’ve only find code to make every letter in the text a different color. Is there any way to turn this to change color in every word instead every letter?

<script type="text/javascript">
       var message = "The quick brown fox.";
       var colors = new Array("#ff0000","#00ff00","#0000ff"); // red, green, blue
       for (var i = 0; i < message.length; i++)
          document.write("<span style=\"color:" + colors[(i % colors.length)] + ";\">" + message[i] + "</span>");
    </script>
  • 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-12T01:44:09+00:00Added an answer on June 12, 2026 at 1:44 am

    Small change required.

    Split the message into an array by space (" ")

       var message = "The quick brown fox.";
       var messageArr = message.split(" ");
       var colors = ["#ff0000","#00ff00","#0000ff"]; // red, green, blue
       for (var i = 0; i < messageArr .length; i++)
       {
          document.write("<span style='color:" + colors[(i % colors.length)] + ";'>" + messageArr[i] + " </span>");
       }
    

    See it on this JSFiddle

    Note: I’ve also changed your colors array definition to using the array literal notation [], which is a slightly better way of declaring an array.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As every developer wants, I wanted to make my code short and simple. but
I wanted to make a simple parser, for a pseudo code like language(kept rigid),
I wanted to make a very simple click counter in Java. It works, but
I don't think this is possible but I wanted to make sure. Lets say
So I wanted to make a game with really clean code and good organization.
I wanted to make a Java based web crawler for an experiment. I heard
I wanted to make a JOptionPane.showOptionDialog with some JTextArea and JLabel . The problem
I wanted to make my top left hand corner of a table rounded in
I wanted to make some simple file recovery software, where I want to try
I wanted to make a basic custom keypad for the iPhone , I did

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.