Wednesday, October 8, 2014

Lab 7

For this lab, lab 7,  the objective was to have time and current date show up on the web page. There are two separate pages, the html page and the java script page .This Lab was mostly done with JavaScript, the only html used was: 
<body onload="myFunction()">
<p id= "demo"></p>
This is basically used to introduce the code that is inside the script style.  In regards to the java script, here is the code that I used:

function myFunction()
{
 alert("page is loaded");
}
var myVar=setInterval(function(){myTimer()},1000);

function myTimer()
{
var d=new Date();
var t=d.toLocaleTimeString();
document.getElementById("demo").innerHTML=t;
}
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
document.write(month + "/" + day + "/" + year)

As you can see in the code the first thing is an alert box when first accessing the page, the box contains the text "page is loaded". The following code sets the timer and show the date. The time is shown in hour minutes and seconds. Regardless of whether it is PM or AM the code will make it so it recognizes the correct time and date and displays it accordingly on the web site. 






No comments:

Post a Comment