Heads up! To view this whole video, sign in with your Courses account or enroll in your free 7-day trial. Sign In Enroll
Preview
Start a free Courses trial
to watch this video
Join me for the final testing and demonstration video to see how our new ability to charge fines to patrons is working.
This video doesn't have any notes.
Related Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign upRelated Discussions
Have questions about this video? Start a discussion with the community and Treehouse staff.
Sign up
Open up the workspace
you were working in or
0:00
open the attached one with
the most updated code.
0:02
We'll take a look at the chart finds
method inside the library class to make
0:04
sure it works as expected and
then we'll be done.
0:08
Testing this method is a little tricky
because we only have one patron object
0:11
that we're working with.
0:15
And, when we call the checkout method on
this patron their book won't be due for
0:16
two weeks.
0:21
If we run the charge fine method right
now, it won't charge a fine to any patron
0:22
because it won't find
any with overdue books.
0:27
That means we have to fudge it a little.
0:30
To do that, we're going to head back
to our book class for a brief moment,
0:32
to look at the outsetter method where we
set a book's due date when we check out.
0:35
Instead of having it set the due
date to two weeks in the future,
0:40
we're going to set it to two
weeks in the past, just for
0:43
the purposes of testing
our charge fines method.
0:46
This way when we run the checkout
method on the patron object, and
0:49
pass in our book object, the book
will be marked as two weeks overdue.
0:53
That means,
when we test out the charge fines method,
0:57
the patron object will be flagged
as having an overdue book and
1:00
we can see if that patron was
correctly charged a fine.
1:04
Once we're done testing the charge fines
method, we'll go back and fix the dueDate.
1:07
So here in our book class all we have to
do is change this plus sign to a minus
1:11
Then we can save and
head back to our index.html file.
1:19
Let's call the checkout method
on the patron object again.
1:24
Now let's call the chargeFines
method on the library object.
1:31
Now, if everything worked as expected, our
patron object should have a book that's
1:38
two weeks overdue, and it should also have
a balance property whose value is $1.40.
1:43
That's the $0.10 fine per day we set
in the library class constructor
1:49
method times 14 days late.
1:53
So let's go back to the index.html file,
1:56
log the patron object then save and
preview to find
1:59
out As you can see,
2:02
our patron object has a balance of 1.4,
or $1.40,
2:11
and the current books due date property
is set to two weeks in the past.
2:16
Great work, I hope you had fun
in this practice session and
2:21
learned some more about how objects
can interact with one another.
2:24
Check the teacher's notes on
this video to learn about other
2:27
OOJS course work you can try and
keep on coding.
2:30
You need to sign up for Treehouse in order to download course files.
Sign upYou need to sign up for Treehouse in order to set up Workspace
Sign up