Docsity

JavaScript Exercises, Lecture notes of Javascript programming

Toggle sidebar
bg1
JavaScript*Exercises*
GEOG*3530/8535*Cartography*&*GIS*
UNO*?*Peterson*
*
7"1.html)
<html>*
<body>*
<script*type="text/javascript">*
<!??*
document.write("Hello*World!")*
//??>*
</script>*
</body>*
</html>*
*
*
7"2.html)
<html>*
<body>*
<script*type="text/javascript">*
<!??*
var*x*=*2***2*
document.write("x*=*",*x)*
//??>*
</script>*
</body>*
</html>*
*
*
7"3.html)
<html>*
<HEAD>**
<SCRIPT*LANGUAGE="JavaScript">*
<!??*Hide*script*from*old*browsers*
function*square(number)*{*
**********return*number***number*
}*
</SCRIPT>*
</HEAD>*
<BODY>*
<SCRIPT>*
**********document.write("The*function*returned*",*
square(5),*".")*
</SCRIPT>*
<P>*All*done.*
</BODY>*
</html>*
*
*
)
7"4common.js)
function*square(number)*{*
**********return*number***number*
}*
*
*
7"4.html)
<HTML>*
<HEAD>*
<TITLE>Referencing*a*file*of*functions</TITLE>*
<SCRIPT*SRC="7?4common.js">*
</SCRIPT>*
</HEAD>*
<BODY>*
<SCRIPT>*
******document.write("The*function*returned*",*
square(5),*".")*
</SCRIPT>*
<P>*All*done.*
</BODY>*
</HTML>*
*
*
7"6.html)
<html>*
<script*type="text/javascript">*
*
function*Time()*
{*
var*currentTime*=*new*Date()*
var*hours*=*currentTime.getHours()*
var*minutes*=*currentTime.getMinutes()*
var*seconds*=*currentTime.getSeconds()*
*
//*call*the*AddZero*function*to*add*a*zero*in*
front*of*numbers*that*are*less*than*10*
hours*=*AddZero(hours)*
minutes*=*AddZero(minutes)*
seconds*=*AddZero(seconds)*
*
//*write*out*the*time*
document.write("<b>"*+*hours*+*"*hours*"*+*
minutes*+*"*minutes*"*+*seconds*+*"*seconds*
</b>")*
}*
*
pf2

Partial preview of the text

Download JavaScript Exercises and more Lecture notes Javascript programming in PDF only on Docsity!

JavaScript Exercises

GEOG 3530/8535 Cartography & GIS

UNO -ยญโ€ Peterson

7 1.html

7 2.html

7 3.html

All done.

7 4common.js function square(number) { return number * number } 7 4.html

Referencing a file of functions

All done.

7 6.html

function AddZero(i) { if (i<10) {i="0" + i} return i }

// call the Time function

  1. Enter all code examples as separate files and debug. You will likely make typing mistakes and this will cause the code examples to not work properly. Make sure they work properly before you go on to step 2.

  2. Change some aspect of these code examples, either in the html or JavaScript. A change might be the use of a different formula, different output text, or different function call.

  3. Put these files in a folder called JavaScript.

  4. Create a new index.htm file for your new JavaScript folder. This index.htm file would look like the following:

    My JavaScript programs ______Name________

    7-ยญโ€1
    7-ยญโ€2
    etc.

  5. Upload the JavaScript folder to your CartGIS folder in the Public folder in myfolder.

  6. Modify your base index.htm file by adding the following lines: My JavaScript Examples JavaScript Examples

  7. Replace your base index.htm file in your CartGIS folder on myfolder.