Before adding the stars I’m trying to figure out why the titles are not appearing on the book objects. I’m sure it’s a simple oversight on my part, but if anyone can help it is sincerely appreciated!
var myBooks = [
{
title: "The Giver",
stars: 4
},
{
title: "Tess",
stars: 5
},
{
title: "Great Gatsby",
stars: 5
}
];
// draw shelf
fill(173, 117, 33);
rect(0, 120, width, 10);
var x = 10;
for (var i = 0; i < myBooks.length; i++){
fill (214, 255, 219);
noStroke();
rect (x, 20, 90, 100);
fill(0, 0, 0);
text (myBooks.title, x, 30, 70, 100);
//image(getImage("cute/Star"), 13 + i * 20, 90. 20, 30);
x = x + 100;
}
Thank you @TfGuy44!! My previous attempts to place the [i] were all wrong.
And now I want to show the stars. Each row of stars should appear within the book object near bottom edge. ***Please see comment line above code for stars placement for the area in question.
var myBooks = [
{
title: "The Giver",
stars: 4
},
{
title: "Tess",
stars: 5
},
{
title: "Great Gatsby",
stars: 5
}
];
// draw shelf
fill(173, 117, 33);
rect(0, 120, width, 10);
var x = 10;
for (var i = 0; i < myBooks.length; i++){
fill (214, 255, 219);
noStroke();
rect (x, 20, 90, 100);
fill(0, 0, 0);
text (myBooks[i].title, x, 30, 70, 100);
//I'm not sure what the syntax here should be to show the stars
image (myBooks[i].stars.getImage("cute/Star"), 13 + i * 20, 90. 20, 30);
x = x + 100;
}