I am trying to create a bookshelf with various books. However, when I attempt to make a new bookshelf for every 4 books, I get an error. Possibly an infinite for loop? What is going wrong? (Khan Academy Program)
An array of books.
var book = [
{
title: "The Giver",
stars: 4,
author: "Lois Lowry",//2.Author property to each book added #1
color: color(0, 120, 42),//3. Property that stores color
recommended: true
},
{
title: "NWT of the Holy Scriptures",
stars: 5,
author: "Jehovah",//2.Author property... #2
color: color(204, 204, 204),//3. Property that stores color
recommended: true
},
{
title: "The Cay",
stars: 4,
author: "Theodore Taylor",//2.Author property... #3
color: color(80, 84, 209),//3. Property that stores color
recommended: true
},
{
title: "The Golden Compass",
stars: 5,
author: "Philip Pullman",//2.Author property... #4
color: color(97, 55, 186),//3. Property that stores color
recommended: true
},
];
Draw bookshelves and books
for(var x = 0; x < book.length; x++){
//Draw books
fill(book[x].color);
rect(5 + 100 * x, 20, 90, 100);
fill(0, 0, 0);
text(book[x].title, 15 + 100 * x, 29, 70, 100);
text(book[x].author,35 + 100 * x, 76, 70, 100);
//Draw leaf for recommended books
if(book[x].recommended === true){
var leaf = getImage("avatars/leaf-red");
image(leaf, 10 + 100 * x, 85,25,25);
}
//Draw stars for star rating
for (var i = 0; i < book[x].stars; i++) {
image(getImage("cute/Star"), 17 + i * 15 + 100 * x, 96 , 15, 25);
}
//Draw bookshelf for every 4 books
for(var y = book.length;y >= 0;y - 4){
// draw shelf
fill(87, 10, 0);
rect(0, 120 + 100 * y, width, 10);
}/// <------ infinite loop?
}
y, like thisy -= 4