Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Practice Object Interaction Checking Out and Returning a Book Demo: Charging Fines to Patrons

Anton Kilk
seal-mask
.a{fill-rule:evenodd;}techdegree
Anton Kilk
Full Stack JavaScript Techdegree Student 11,256 Points

I run this code and keep getting 1.5 as dailyFine. Not 1.4 as shown in explanation and as should be for 14 days.

Indeed, if you check the 'daysLate' value, it gives '15'. Why? Snapshot:https://w.trhou.se/n0iw7i49xy

Steven Parker
Steven Parker
229,732 Points

Please post your code (with Markdown formatting) or make a snapshot of your workspace and post the link to it here.

6 Answers

rydavim
rydavim
18,813 Points

The snapshot you posted above works as expected for me. dailyFine is 0.1, daysLate is 14, and balance is 1.4. I would try a hard refresh, but I can't think of a reason why it might be coming back differently for you with the same code. If you're still having issues, what browser are you using?

Steven Parker
Steven Parker
229,732 Points

I'm not seeing the issue, the "daysLate" amount logged on the console is 14.

But where's the code that you use to show the amount?

Anton Kilk
seal-mask
.a{fill-rule:evenodd;}techdegree
Anton Kilk
Full Stack JavaScript Techdegree Student 11,256 Points

Strange. I still get 15 days and 1.5 as balance. I updated the code with 'console.log(patron.balance);' to see the balance as well. Here is the snapshot once again: https://w.trhou.se/5xt1d87pl0. Please let me know, if you know what can be the issue. I use Google Chrome Version 77.0.3865.90 (Official Build) (64-bit)

rydavim
rydavim
18,813 Points

I'm still getting the expected behavior.

With the way JS implements Date, this shouldn't matter - but what timezone are you in? If you log out now and dateDiff, what do you get?

Anton Kilk
seal-mask
.a{fill-rule:evenodd;}techdegree
Anton Kilk
Full Stack JavaScript Techdegree Student 11,256 Points

Hi rydavim ! I am in Helsinki timezone: Eastern European Summer Time Time zone in Helsinki (GMT+3) Friday, 18 October 2019, 10.29

I get these answers: dateDiff: Thu Jan 15 1970 02:00:00 GMT+0200 (Eastern European Standard Time) now: Fri Oct 18 2019 10:36:06 GMT+0300 (Eastern European Summer Time) Something wrong with dateDiff variable, isn't it? I wonder, why does it work in your region...

I have same issue and I don't see any solution so far. To get the same value of fine I have to manipulate the days from when It counts the fine.

Steven Parker
Steven Parker
229,732 Points

Start a fresh question and show your own code in it.

I get the same result (1.5) even when running the code provided by Ashley (from workspace) Using Google Chrome v 92 and my timezone is +7 GMT