27-06-2012, 04:54 PM
Javascript
Javascript.pdf (Size: 38.73 KB / Downloads: 57)
Reminder
This problem builds on the countup.html program
shown in class, with code included on the class handout,
and code also in the Code section of that class on
the website. The purpose of this program is to remind
you of some event after a specified number of seconds.
To draw your attention to the reminder, the table
flashes alternately between red and green.
Columns of Elephants
Now that you can place one elephant and get it to
walk across the plain, you can extend the program to
create a column of elephants crossing the plain.
+ (e) Write a new button marked place herd that
asks for a cell number in the range 0..8. The program
then draws a column of elephants extending
downward from that cell. For example, if the
user specifies cell 2, the program draws five elephants
at cells 2, 11, 20, etc.
Timed Automation
Elephants do not need a button-push to move. Once
started, they can keep moving on their own. The walk
button calls a function that does not yet exist.
+ © Write the walk_elephant() function. This
function must work as follows: When the button
is pressed, the elephant moves one cell forward
each second. If the user presses the ¬ button, the
elephant moves backwards one cell each second.
If the user presses the ® button, the elephant
starts moving forward. HINT: You will need a
global variable that keeps track of whether the
elephant is moving forward or backward.