JavaScript
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++ (http://planetmath.org/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); } }
References
- 1 A. Danesh Javascript in 10 Simple Steps or Less Indianapolis: Wiley (2004)
- 2 D. Flannagan JavaScript Pocket Reference New York: O’Reilly (1998)
.1 External links
http://bobspoetry.com/eVoteDemo.htmlElectronic 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.
http://www.btinternet.com/ se16/js/factor.htmHenry Bottomley’s Prime Factors Calculator Uses trial division to factor input integers.
Title | JavaScript |
---|---|
Canonical name | JavaScript |
Date of creation | 2013-03-22 16:52:13 |
Last modified on | 2013-03-22 16:52:13 |
Owner | PrimeFan (13766) |
Last modified by | PrimeFan (13766) |
Numerical id | 6 |
Author | PrimeFan (13766) |
Entry type | Definition |
Classification | msc 68N15 |
Classification | msc 03-04 |
Synonym | JScript |
Synonym | ECMAScript |