I have an error where whenever I try to put multiple things in one draw box (example: drawbox (colors ) ) it will only read the first letter of the color that represents. So if 1is set to white, it will say error : w is not a valid color for draw box
Each set of brackets will try to access a specific item from whatever it is attached to.
 means, get the first item, and
 means get the second item.
colorswill get the second item from
colorswhich is the string
colorswill get the first item from
colors, which was the string
'white', and the first item in the string is the first letter,
Another way to look at this is:
( colors )
drawBox() can only create 1 box at a time, you need to use 2
drawBox() calls to make 2 boxes.
New to the language of programming and enjoying it.
Please advise if I will come upon a project where just inserting a new line and indicating/defining what my variables are ( 0=black and 1=white), the code will in draw boxes automatically will run?
Not sure if my question makes sense when I viewed the example code(below) I thought we had to insert a new line to define what 0 and 1 was
var groceries = ['apples', 'bananas', 'oranges']; var fruit = groceries;
1 refer to the location of each item in the array. An item’s location in an array is called its “index”.
Indexing starts at
0, meaning that the first item in an array is at index
In this puzzle, the
colors array looks like this:
var colors = ['black', 'white'];
'black' is at
'white' is at
Hope this clears things up! Let me know if you have any more questions.