# 3 Rectangles - 3 Colors

**URL:** https://forum.kirupa.com/t/3-rectangles-3-colors/644115
**Category:** Uncategorized
**Created:** [September 8, 2020, 3:59pm UTC](https://forum.kirupa.com/t/3-rectangles-3-colors/644115 "2020-09-08T15:59:18Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![John\_Stern](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/john_stern/32/12050_2.png) [@John\_Stern](https://forum.kirupa.com/u/John_Stern)
#### Post date: [September 8, 2020, 3:59pm UTC](https://forum.kirupa.com/t/3-rectangles-3-colors/644115/1 "2020-09-08T15:59:18Z")

</div>

fill(173, 117, 33); //draws bookshelf  
rect(0, 120, width, 10);

var library = [ //array of 3 objects

{ title:”I Know Why The Caged Bird Sings”,  
author:”R. Michener”,  
stars:4,  
color:(100 + i_50, 100 + i_50, 100 + i\*50)},

{ title:”Alaric the Goth”,  
author:Boin,  
stars:4,  
color:(100 + i_50, 100 + i_50, 100 + i\*50)},

{ title:”Caesar Invades Gaul”,  
author:”Goldsworthy”,  
stars:4,  
color:(100 + i_50, 100 + i_50, 100 + i_50)}  
];  
//draws the rectangle for each book with different colors  
for(var i = 0; i \< library.length; i++) {  
fill(100 + 50_i,100 + 50_i,100 + 50_i);  
rect(10 + 120\*i,20,90,100);  
}

ultimately the idea is to take ALL the info in the 3 objects and visualize them like so -

 ![Screen Shot 2020-09-08 at 8.45.31 AM](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/2X/f/f7a1c91bb83991a8223fcbc0a97f365c6602d45d.png)

but this is quite a complex undertaking(for me anyway) and with the above code, all I wanted to do was simply see whether I could get a for loop to  
- place the rectangular outline on the bookshelf  
- get a different color for each of the rectangles  
I will worry about the title / author display as well as the stars later. I have a feeling that I should be calling the color property in my for loop to implement the different colors that I want but I can’t see how to do this

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [September 8, 2020, 4:33pm UTC](https://forum.kirupa.com/t/3-rectangles-3-colors/644115/2 "2020-09-08T16:33:34Z")

</div>

Looks like you’re still struggling with syntax errors. First theres a string without quotes:

```
author:Boin,

```

should be

```
author: "Boin",

```

then it looks like all your other problems are a bunch of cases of `i50` or `50i` that should be `i*50` or `50*i`.

---

<div class="post-metadata">

### Author: ![John\_Stern](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/john_stern/32/12050_2.png) [@John\_Stern](https://forum.kirupa.com/u/John_Stern)
#### Post date: [September 9, 2020, 1:52am UTC](https://forum.kirupa.com/t/3-rectangles-3-colors/644115/3 "2020-09-09T01:52:41Z")

</div>

Unreal ! That after all this practise, I am still making these errors. Thanks for pointing them out. I will struggle on.

---

<div class="post-metadata">

### Author: ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)
#### Post date: [September 9, 2020, 2:30am UTC](https://forum.kirupa.com/t/3-rectangles-3-colors/644115/4 "2020-09-09T02:30:18Z")

</div>

You’ll get there 😉
