This forum is now read-only. Please use our new forums at discuss.codecademy.com.

Animate Your Name Forum

View Course

21 points
8cd6396908ce5fc39356512c401d48f3?s=140&d=retro
Submitted by
karan_4
over 3 years ago

I want to understand why "red" doesn't work

i just wanted to understand that in the syntax given below:
var letterColors=["red",green,blue,purple];
it hides the red color in the name.
how it is doing that.?? i did not get the logic behind that.


0 votes

permalink

Let's see if I can explain this.

There are different types of data.

One type is a string. Strings are indicated by putting quotes around text, like "red".

Another type is an array. Arrays are groups of data. Arrays are indicated by putting square brackets around the data, like [0, 100, 63]. We can give arrays a name, like red = [0, 100, 63]

In the first case, "red" just means those 3 characters, in the second case, red represents that array with three numbers. Those numbers can be used to tell the computer how to create the colour that we know as red.

So in your example letterColors = ["red", green, blue, purple], the "red" can not be converted to a colour because it is just those three letters, so you no longer see red in your animation.

3692 points
55df2afa95e3787b9200005e_359368177
Submitted by
Judy
over 3 years ago


0 votes

permalink

Try the next and your code it will be fixed it:
var letterColors = [red, orange, green, blue, purple];

365 points
543fc82f631fe988640020d7_382532424
Submitted by
Tobias P√°ez
about 3 years ago