PlanetMath (more info)
 Math for the people, by the people.
Encyclopedia | Requests | Forums | Docs | Wiki | Random | RSS  
Login
create new user
name:
pass:
forget your password?
Main Menu
JavaScript (Definition)

JavaScript (called JScript by Microsoft and 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 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 calcGCD() function.

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);
}
}

Bibliography

A. Danesh Javascript in 10 Simple Steps or Less Indianapolis: Wiley (2004)
2
D. Flannagan JavaScript Pocket Reference New York: O'Reilly (1998)

External links

Electronic Voting Demonstration 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.

Henry Bottomley's Prime Factors Calculator Uses trial division to factor input integers.



Anyone with an account can edit this entry. Please help improve it!

"JavaScript" is owned by PrimeFan.
(view preamble)

View style:

Other names:  JScript, ECMAScript

Cross-references: function, span, body, code, Euclid's algorithm, greatest common divisor, integers, syntax, Java, word, calculators, BASIC, language
There are 4 references to this entry.

This is version 2 of JavaScript, born on 2007-03-27, modified 2007-03-27.
Object id is 9120, canonical name is JavaScript.
Accessed 87 times total.

Classification:
AMS MSC68N15 (Computer science :: Software :: Programming languages)

Pending Errata and Addenda
None.
[ View all 1 ]
Discussion
Style: Expand: Order:
forum policy

No messages.

Interact
rate | post | correct | update request | add derivation | add example | add (any)