I have to make "days left" page on a browser so when employees open their browser they see how many days are left to their system upgrade. The code is provided for me I just have to modify it. Here is what I have so far. I will also post the original code given to us. It's very simple but I'm very new to this so need help. Thank you in advance. <!DOCTYPE html> <html> <body> <script type="text/javascript"> var today = new Date(); var UpgradeDay = new Date("March 19, 2015"); var msPerDay = 24 * 60 * 60 * 1000 ; var timeLeft = (UpgradeDay.getTime() - today.getTime()); var days = timeLeft / msPerDay; var daysLeft = Math.floor(daysLeft); document.write("<P>There are only<BR> <H4>" + 60 + " days </H4> Until Your Computer Upgrade<P>"); </script> </body> </html> Code (markup): ORIGINAL>>>> <!DOCTYPE html> <html> <body> <script type="text/javascript"> var today = new Date(); var UpgradeDay = new Date("January 19, 2015"); var msPerDay = 24 * 60 * 60 * 1000 ; var timeLeft = (UpgradeDay.getTime() - today.getTime()); var days = timeLeft / msPerDay; var daysLeft = Math.floor(days); document.write("There are only<BR> <H4>" + daysLeft + " days </H4> Until Your Computer Upgrade<P>"); </script> </body> </html> Code (markup):
Please find the code below. Let me know if you face any problems <!DOCTYPE html> <html> <body> <script type="text/javascript"> var today = new Date(); var UpgradeDay = new Date("March 22, 2016"); var msPerDay = 24 * 60 * 60 * 1000 ; var timeLeft = (UpgradeDay.getTime() - today.getTime()); var daysLeft = Math.round(timeLeft / msPerDay); var daysLeft = Math.floor(daysLeft); if( daysLeft < 0 ) document.write("<P>Your license expired by <BR> <H4>" + daysLeft + " days </H4> Please upgrade to continue <P>"); else document.write("<P>There are only<BR> <H4>" + daysLeft + " days </H4> Until Your Computer Upgrade<P>"); </script> </body> </html> Code (markup):
Sorry but I don't understand the purpose of the modification? What is the goal? document.write is not best practice. Better use createElement() -> createTextNode() -> appendChild(). Or at least innerHTML method.
The instructions are just fine. You may want to check what's the higher date, the current one or the upgrade date. If the upgrade date is higher, then you show the message "X days for the next system update". Otherwise, it means that the upgrade date is now old and you can show the message "The last system update was X days ago. There are no upcoming updates". You also might want to use the abs function to get the different between the current and the upgrade date so you don't get any minus numbers. Hope it helps