Operation Random!
Your mission, should you decide to accept it, is to define a fruitful
function named randomColor that has no input parameters
and returns a string. Your function should perform the
following two steps:
- Generate a random integer — you may invoke the
function randomInt() that is provided to help with
this task. The randomInt() function takes one
argument, a number, and returns an integer from 0 up to but not
including the number.
- Return a string that is the name of a randomly chosen color. Your
function should generate at least five colors, such as "red",
"green", "magenta", "cyan" and "yellow." Please do not include
"blue" as a possible color!
Write your function definition on the whiteboard set aside for your
team. After your definition has been cleared by one of your mission
leaders (Scott or Anna), implement and test your function as follows:
- Save a copy
of
on your Desktop. It's probably easiest to visit the file and then do
"File > Save Page As."
- You do not need to make any changes to this file!
You are welcome to look at it. Notice that it loads a
JavaScript file called
. That's the file
you'll be creating.
- Open Atom and type in your definition for the
function (just the function definition, with no <script> tags)
- Save the file on your Desktop with the name
- In your browser, use Open File in the File
menu to open the file from your Desktop
- Debug! When your function is working, the page should
look exactly like this:
Operation Random
A header with three words in random colors will appear below, after you add your
definition of the randomColor() function:
When you're done, upload the code file to the
MI6 folder in the public_html
directory of the cs110d account. Your mission
leaders will give you the password.