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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T08:56:21+00:00 2026-06-04T08:56:21+00:00

Note: I have read https://meta.stackexchange.com/questions/128548/what-stack-overflow-is-not/129362#129362 It says try to write the code yourself and

  • 0

Note: I have read https://meta.stackexchange.com/questions/128548/what-stack-overflow-is-not/129362#129362

It says “try to write the code yourself and post what you’ve tried when you run into problems.” which is what I am doing here.

The original PHP code:

$text = "Hello world, I am rainbow text!";
$texty = '';
    $colors = array('ff00ff','ff00cc','ff0099','ff0066','ff0033','ff0000',
                    'ff3300','ff6600','ff9900','ffcc00','ffff00','ccff00',
                     '99ff00','66ff00','33ff00','00ff00','00ff33','00ff66',
                     '00ff99','00ffcc','00ffff','00ccff','0099ff','0066ff',
                     '0033ff','0000ff','3300ff','6600ff','9900ff','cc00ff'); 
        $i = 0;
$textlength = strlen($text);
while($i<=$textlength){
foreach($colors as $key=>$value){
    if (isset($text[$i])) {
        $texty .= "<font color=\"#".$value."\">".$text[$i]."</font>";
    }
    $i++;
}
$texty = str_replace("> <",">&nbsp;<",$texty);
echo $texty;
}

What I’ve butchered it down to:

var text = "Hello world, I am rainbow text!";
var texty = '';
colors = new Array

('ff00ff','ff00cc','ff0099','ff0066','ff0033','ff0000',
 'ff3300','ff6600','ff9900','ffcc00','ffff00','ccff00',
 '99ff00','66ff00','33ff00','00ff00','00ff33','00ff66',
 '00ff99','00ffcc','00ffff','00ccff','0099ff','0066ff',
 '0033ff','0000ff','3300ff','6600ff','9900ff','cc00ff'); 
var i = 0;

var textlength = text.length;
var key = '';
var value = '';
while(i <= textlength){
for each(colors as key=>value){
    if (text[i] != undefined) {
        texty .= "<font color=\"#" + value + "\">" + text[i] + "</font>";
    }
    i++;
}
texty.replace("> <",">&nbsp;<");
//document.write(texty);
}

I’ve been testing this as Javascript, which is why I have document.write commented in the code. However, I still cannot get it to work. I hate to be so vague but… can someone tell me where I screwed up?

  • 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-04T08:56:22+00:00Added an answer on June 4, 2026 at 8:56 am

    Got something with your code, but didnt get what you trying to do.
    Check out fiddle.

    http://jsfiddle.net/ymutlu/pKCcS/

    this looks better…

    http://jsfiddle.net/pKCcS/2/

    posted code here, in case i delete fiddle link.

    var text = "Hello world, I am rainbow text!";
    var texty = '';
    colors = ['ff00ff','ff3300','ff6600','ffff66','00ff99','00ffcc','00ffff','00ccff','0099ff','0066ff','0033ff','0000ff','3300ff','6600ff','9900ff','cc00ff']; 
    var i = 0;
    
    
    var textlength = text.length;
    var key = '';
    var value = '';
    while(i <= textlength){
        var t = text.charAt(i);
    
        if (t!= undefined) {
            texty += "<font color=\"#" + colors[i%colors.length] + "\">" +  t + "</font>";
        i++;
    }
    }
    
    texty.replace("> <",">&nbsp;<");
    document.write(texty);
    

    ​

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

Sidebar

Related Questions

NOTE: I have a related question here (http://stackoverflow.com/questions/6915055/are-jsf-views-shared-between-users) but that deals with a few
I have read on MSDN( see Important note ) that RSACryptoServiceProvider must be disposed.
Note - I do not have access to a database and cannot use PHP,
Note: I'm using Google Chrome Currently I have this test page http://www.evecakes.com/doodles/canvas_size_issue.htm It should
NOTE: The libraries MCrypt support depend on have not been updated in years and
I want to read plain/text from an Https server. I have tried various codes
I have read and re-read this page, as well as run the samples: http://code.google.com/chrome/extensions/background_pages.html
I have the following post button that i use for paypal transactions: <form action=https://www.sandbox.paypal.com/cgi-bin/webscr
(NOTE: I have read http://shiningthrough.co.uk/Select-helper-methods-in-Ruby-on-Rails , but still don't know what to pick) I
Quick note: I'm using the SoundPool class http://developer.android.com/reference/android/media/SoundPool.html What I have here is a

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.