Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Hello Im currently writing a program for the Khan Academy project called bookshelves. I've completed most of the code but I'm having alot of trouble

Hello Im currently writing a program for the Khan Academy project called bookshelves. I've completed most of the code but I'm having alot of trouble implementing a global variable. Im supposed to have the number of apps per shelf be a global variable at the top of the program. That is, all shelves, except possibly the last shelf, will have the number of apps that you set in the global variable, but the last shelf may have less if the number of apps you have is not divisible by the number. For instance, if there are 7 apps and the global variable is set to 3, the your program should print two shelves of 3 apps and one shelf of 1 app. Then if you change the global variable to 4, then your program would print one shelf of 4 apps and one shelf of 3 apps.

I will paste my code here.

----------------------------------------------------

var book = { title: ["My initial", "Funny Face", "My House", "My Animal", "Dancing Animals", "Racing Animals","Dancing Animals Fun", "Racing Animal Fun","Resize Animal", "Music Quiz","Zoo","Dry Animal", "Ball Follow"], author: ["Camren Woodstock","Camren Woodstock","Camren Woodstock","Camren Woodstock","Camren Woodstock","Camren Woodstock","Camren Woodstock","Camren Woodstock","Camren Woodstock","Camren Woodstock","Camren Woodstock","Camren Woodstock"], stars: [5, 4, 3, 2, 1] }; var a = 1; var b = 20; var c = 0; var d = 0; while (120 * a < 400) { // draw shelf fill(173, 117, 33); rect(0, 120 * a, width, 10); a++; } // draw one book for (var j = 0; j < book.title.length; j++) { if ((10 + 100 * c) + 80 > 400) { b += 120; c = 0; d++; } fill(random(80,200), random(50,240), random(40,200)); rect(6 + 100 * c, b, 90, 100); fill(0, 0, 0); textSize(13); text(book.title[j], 10 + 100 * c, 5 + b, 70, 100); textSize(10); text("By " + book.author[j], 10 + 100 * c, 51 + b, 70, 100); for (var i = 0; i < book.stars[d]; i++) { image(getImage("cute/Star"), (12 + i * 16) + 100 * c, 70 + b, 20, 30); } c ++; }

------------------------------------------------------

The global variable is booksPerShelf and when I change it to 3 it should be 3 books per shelf and when I change the number to 4 it will be 4 books per shelf.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Intelligent Information And Database Systems Asian Conference Aciids 2012 Kaohsiung Taiwan March 19 21 2012 Proceedings Part 3 Lnai 7198

Authors: Jeng-Shyang Pan ,Shyi-Ming Chen ,Ngoc-Thanh Nguyen

2012th Edition

3642284922, 978-3642284922

More Books

Students also viewed these Databases questions

Question

4. What actions should Bouleau & Huntley take now?

Answered: 1 week ago