To refer to window property: window.propertyName.

The window object is the topmost object in the object hierarchy, therefore it can be shortened to: propertyname, and window is the default object.

Now try to generate the following output on the browser. See image.

The above can be generated in IE from the following code

< html >
< head >
< title > Start and stop a clock < /title >
< /head >
< body >
< input type="text" size= "60" id="theclock" / >
< script type="text/javascript" >
var setIntervalID = window.setInterval("setClock()",1000);
function setClock()
{
var now = new Date();
document.getElementById("theclock").value=now.toLocaleString();
}
function stopClock()
{
clearIntervalID=window.clearInterval(setIntervalID);
}
< /script >
< button onclick="stopClock()" >Stop< /button >
< /body >
< /html >

Exercise 1

Modify the above script so that you can display the clock as the following with only time portion shown See image.

Note the time shall be current local time for both figure above.

In order to output the above, you need to just output the time portion of the local string. To find the Date object and its properties, please refer to the link

http://www.w3schools.com/jsref/jsref_obj_date.asp

The following script will generate three windows using arrays. Firstly it will create a page with a button ‘start to create windows’. When clicked, three windows will appear on the screen in specified locations. See image.

Here is the code

< html >
< head >
< title >Opening and Closing Windows< /title >
< script type="text/javascript" >
var myWindows = new Array();
var windowNo = new Array("Window1", "Window2", "Window3");
var leftPos =[200, 450, 700];
function createWindows()
{
for (i=0; i < 3; i++)
{
var j= i*200;
myWindows[i] = window.open("http://www.montclair.edu/", windowNo[i], "height=200,width=200,left="+leftPos[i])
}
}//end of createWindows
< /script >
< /head >
< body >
< h1 >Open and Close windows< /h1 >
< h2 >Press buttons to open and close windows< /h2 >
< form >
< input type="button" id="createWindowsbtn" value="start to create windows" onclick="createWindows();" >
< /form >
< /body >
< /html >

Refer to the following for window open method

http://www.w3schools.com/jsref/met_win_open.asp

Exercise 2

Try to generate several windows on random locations using random number generator we learned.

Academic Honesty!
It is not our intention to break the school's academic policy. Posted solutions are meant to be used as a reference and should not be submitted as is. We are not held liable for any misuse of the solutions. Please see the frequently asked questions page for further questions and inquiries.
Kindly complete the form. Please provide a valid email address and we will get back to you within 24 hours. Payment is through PayPal, Buy me a Coffee or Cryptocurrency. We are a nonprofit organization however we need funds to keep this organization operating and to be able to complete our research and development projects.