"This new program showcases an array of books with the use of a loop, allowing multiple books to be displayed in a row."
I am looking to implement the for loop to showcase each book stored in the array. Currently, the 'i' variable remains at 0 and needs to be manually set to 1 to display the next book.
var books = [
{title: "Pride and Prejudice",
stars: 5,
like:true},
{title: "To Kill a Mockingbird",
stars: 4,
like:false}
];
// draw shelf
for (var s = 1; s < 4; s++) {
fill(173, 117, 33);
rect(0, s * 120, width, 10);
}
// draw all books
for (var i = 0; i < books.length; i++) {
var currentBook = books[i]; //accessing individual books from the array
fill(214, 255, 219);
rect(i * 97, 20, 90, 100);
fill(0, 0, 0);
text(currentBook.title, i * 97, 29, 70, 100);
for (var rating = 0; rating < currentBook.stars; rating++) {
image(getImage("cute/Star"), i * 100 + rating * 19, 90, 18, 30);
}
}