1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Need help for school coding assignment. Newbie.

Discussion in 'JavaScript' started by Ashley Martinez, Mar 19, 2016.

  1. #1
    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):

     
    Ashley Martinez, Mar 19, 2016 IP
  2. msibi

    msibi Greenhorn

    Messages:
    1
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    23
    #2
    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):
     
    msibi, Mar 20, 2016 IP
    qwikad.com likes this.
  3. Blizzardofozz

    Blizzardofozz Well-Known Member

    Messages:
    132
    Likes Received:
    9
    Best Answers:
    1
    Trophy Points:
    118
    #3
    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.
     
    Blizzardofozz, Mar 23, 2016 IP
  4. fisasti

    fisasti Active Member

    Messages:
    42
    Likes Received:
    5
    Best Answers:
    2
    Trophy Points:
    58
    #4
    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
     
    fisasti, Apr 12, 2016 IP
  5. Robert4647

    Robert4647 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    1
    #5
    The team at New Assignment Help Australia truly exceeded my expectations! I used their Coding Assignment Help for a challenging web development task, and the results were impressive. They delivered a project that was both technically sound and visually appealing. What sets them apart is their attention to detail and commitment to quality. The entire process was stress-free, and the final product helped me secure top grades. If you’re looking for a trusted service for your assignments, I wholeheartedly recommend them!
     
    Robert4647, Dec 14, 2024 IP