Title Missing From Book Cover

var library = [			//array of 3 objects
{	title:”I Know Why The Caged Bird Sings”,
	author:”R. Michener”,
	stars:4		},
	{	title:”Alaric the Goth”,
	author:"Boin",
	stars:4		},
	{	title:”Caesar Invades Gaul”,
	author:”Goldsworthy”,
	stars:4		}
	];

fill(140, 107, 7); // brown bookshelf
rect(0,120,width,20);
for(var i = 0; i < 3; i++)  {
    fill(100 + 100*i, 200, 100 + 100*i); // 3 book covers different colors
    rect(20 + 110*i,20,90,100);
    textSize(15);
    fill(93, 105, 25);
	text(library.title[i],20 + 110*i,60,90,40,80,30);
}

I thought this code would place the titles of the books on to the book covers in the top 1/3 of the cover but no - nothing happens - I think the code looks OK so I don’t see where I am going wrong

I’m seeing some weird forum formatting in the code which makes me think some of the missing * from before (and now) might be because you’re not using the forum code formatting to format your code which causes the code to instead format the text as italics instead of showing the multiplication symbols :stuck_out_tongue: I’m going to edit your post to fix those things, but in the future you can wrap your code with triple back ticks (```) to fix this…

The error with the code is this line

text(library.title[i],20 + 110*i,60,90,40,80,30);

The problem here is that library is the array, not title. Its the array you want to use the square brackets with - to get the i’th value in that array. title is the property of that i’th value. What it should be is:

text(library[i].title,20 + 110*i,60,90,40,80,30);

so this code at least gives me a bookshelf with 3 books each a different color

fill(140, 107, 7); // brown bookshelf
rect(0,120,width,20);
for(var i = 0; i < 3; i++) {
fill(100 + 100i, 200, 100 + 100i); // 3 book covers different colors
rect(20 + 110*i,20,90,100);
}

but when I add the complete code that I thought would place the title on the books (btw the complete code includes fixing my previous error of the misplaced [i] in the line

text(library[i].title,20 + 110*i,60,90,40,80,30);

such that the code looks like

var library = [ //array of 3 objects
{ title:”I Know Why The Caged Bird Sings”,
author:”R. Michener”,
stars:4 },
{ title:”Alaric the Goth”,
author:“Boin”,
stars:4 },
{ title:”Caesar Invades Gaul”,
author:”Goldsworthy”,
stars:4 }
];

fill(140, 107, 7); // brown bookshelf
rect(0,120,width,20);
for(var i = 0; i < 3; i++) {
fill(100 + 100i, 200, 100 + 100i); // 3 book covers different colors
rect(20 + 110i,20,90,100);
textSize(15);
fill(93, 105, 25);
text(library[i].title,20 + 110
i,60,90,40,80,30);
}

well now my bookshelf and books disappear to say nothing of the titles showing !
Yikes ! I am going backwards !