Reputation: 1
In my intro coding class I'm having trouble warping my head around making custom colors, and the teacher couldn't explain it well enough, and CodeHS also doesn't explain well enough either.
*// You can also make your own color by giving a red, green,
// and blue component like
//*
var color = new Color(r, g, b);
*// Another way to set the color of an object is to use a
// string with the hexadecimal color value with setColor.
// For example, to set a rect object to be pink:
//*
rect.setColor("#FF66CC");
This is all CodeHS explains and doesn't give good examples.
Can someone mock up an example of some code a newbie can understand?
Upvotes: 0
Views: 2199
Reputation: 35
I noticed you're working in CodeHS, here's a good example of how to use it.
var -var name- = new Color(r, g, b);
the R, G, and B represent the Red, Blue, and Green values of the color. You can look up RGB values for custom colors on Google. You can then use the color on a shape or something other by this example-
-var name-.setColor(-var name of color-);
Hope this helps.
Upvotes: 0
Reputation: 34234
I guess, you are confusing JavaScript and Java.
There is no such object like Color
or Rectangle
in JavaScript.
However, there are such objects and methods in Java
:
Upvotes: 1