Skip to content
Playback Speed:

In this video, you will add to your Auto Editor program, so it highlights each overused word or phrase in a different, random color.

For example, the word so will be highlighted in one color, while the word very will be highlighted in another color.

To do this, you will reuse code that others created.

In programming, someone else may have already written the code you need.

If you are not sure how to add to your program, you can usually find help on the internet.

You need code that generates random colors to highlight each word.

To start, perform an internet search to determine if someone has previously written code like this.

Google Apps Script and Javascript are nearly identical, and Javascript is widely used.

So, searching for information about Javascript usually works.

On this site, a user asked for help generating a random color.

The author received a lot of answers!

In programming, there are often many workable solutions to a single problem.

This code generates a random number for the color each time your Auto Editor searches for a new word.

To use this code with your program, first create a variable called background.

At the top of the find text function, type V-A-R, space, background and an equals sign.

The code is also found in the instructions section on this page.

Copy the code, and paste it in your code to set the variable.

To test the code you added, set a breakpoint after the line that generates a random color.

Then, run the highlight problem function.

Click the debug button.

The debugger window opens, and the variable background is set to a number.

To see what color this represents, search for it on the internet.


This is the color the code will use.

Your hex color code will probably be different since the computer picks the numbers at random.

Right now, the Auto Editor highlights all words in the color you specified.

To generate random colors, replace the hex code with the background variable.

Do not use quotes this time.

Try it out.

Remove the highlighting from your document, then run the code again.


Different words are highlighted in different, random colors.

Return to your code, and add a comment describing what this line does.

The code you copied is written, so others can use it.

When you use other people's code that you find online, it's a good practice to credit their work.

Now, it's your turn.

Generate a random color number, and store it in the variable background.

Then, replace the hex code in your set background color code with background.

Try it out!


  1. Generate a random color number and store it in a variable.
  2. Use that variable for the background color int he "set background color" code you have already written.
  3. Give credit to the source of the code.
  • "Random Color generator in Javascript" by Stack Overflow (
  • "JavaScript random() Method Page" by W3schools (
  • "JavaScript random() Method Try It Page" by W3schools (
  • "JavaScript random() Method Try It Page" by W3schools (