-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path68N15-JavaScript.tex
More file actions
84 lines (69 loc) · 3.37 KB
/
68N15-JavaScript.tex
File metadata and controls
84 lines (69 loc) · 3.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
\documentclass[12pt]{article}
\usepackage{pmmeta}
\pmcanonicalname{JavaScript}
\pmcreated{2013-03-22 16:52:13}
\pmmodified{2013-03-22 16:52:13}
\pmowner{PrimeFan}{13766}
\pmmodifier{PrimeFan}{13766}
\pmtitle{JavaScript}
\pmrecord{6}{39120}
\pmprivacy{1}
\pmauthor{PrimeFan}{13766}
\pmtype{Definition}
\pmcomment{trigger rebuild}
\pmclassification{msc}{68N15}
\pmclassification{msc}{03-04}
\pmsynonym{JScript}{JavaScript}
\pmsynonym{ECMAScript}{JavaScript}
\endmetadata
% this is the default PlanetMath preamble. as your knowledge
% of TeX increases, you will probably want to edit this, but
% it should be fine as is for beginners.
% almost certainly you want these
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsfonts}
% used for TeXing text within eps files
%\usepackage{psfrag}
% need this for including graphics (\includegraphics)
%\usepackage{graphicx}
% for neatly defining theorems and propositions
%\usepackage{amsthm}
% making logically defined graphics
%%%\usepackage{xypic}
% there are many more packages, add them here as you need them
% define commands here
\begin{document}
{\em JavaScript} (called {\em JScript} by Microsoft and {\em ECMAScript} by the WC3) is an interpreted scripting language primarily used on the Internet to perform basic input validation and to implement basic Web calculators. Other than the fact that Netscape Corporation licensed the use of the word "Java" from Sun, that JavaScript uses Java's \PMlinkname{C++}{C}-like syntax and that JavaScript is deployed on the Internet, there is nothing in common between Java and JavaScript. The major modern Web browsers implement JavaScript: Netscape's Navigator, of course, and also Microsoft's Internet Explorer, Mozilla's Mozilla and FireFox, Opera, etc.
The following JavaScript program takes two integers as inputs and outputs their greatest common divisor using Euclid's algorithm. This is intended for Microsoft Internet Explorer 4.0 or higher; the code is placed between script tags in the head element of the HTML page, the body element should have a form element with appropriately labelled inputs, a span of text where the script will write the results to, and a button that calls the \verb=calcGCD()= function.
\begin{verbatim}
function calcGCD(a, b) {
wA = a;
wB = b;
while ( wB > 0 ) {
tempA = wA;
wA = wB
wB = tempA % wB;
}
return wA;
}
function goGCD() {
x = parseInt( document.forms[0].Xval.value );
y = parseInt( document.forms[0].Yval.value );
if ( isNaN( x ) || isNaN( y ) ) {
alert( "Please enter integers." );
} else {
document.all.GCDResultLine.innerText = "The greatest common divisor of " + x + " and " + y + " is " + calcGCD(x, y);
}
}
\end{verbatim}
\begin{thebibliography}{2}
\bibitem{ad} A. Danesh {\it Javascript in 10 Simple Steps or Less} Indianapolis: Wiley (2004)
\bibitem{df} D. Flannagan {\it JavaScript Pocket Reference} New York: O'Reilly (1998)
\end{thebibliography}
\subsection{External links}
\PMlinkexternal{Electronic Voting Demonstration}{http://bobspoetry.com/eVoteDemo.html} Since this voting demo is implemented in JavaScript rather than Java, the source code may be inspected using the Web browser's View Source command. This is not the case of Diebold voting machines.
\PMlinkexternal{Henry Bottomley's Prime Factors Calculator}{http://www.btinternet.com/~se16/js/factor.htm} Uses trial division to factor input integers.
%%%%%
%%%%%
\end{document}