


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Examples and explanations of javascript code embedded in html to create interactive web pages. Topics include using browser objects and functions for writing on the page, mathematical and logical operators, and creating a simple calculator.
Typology: Exercises
1 / 4
This page cannot be seen from the preview
Don't miss anything!



Lesson 13 JAVA SCRIPTING
Java script examples
Javascript Example
Result is shown in Fig. 1 below.
Fig. 1
Note we can embed JavaScript code/instructions in the plain HTML code with the help of tags. In the above example ‘alert’ is the function/method of a predefined browser object that is, window object, and is used to create alert boxes or popup messages on the window. ‘//’ is used in JavaScript to provide comments. Here, we use ‘//’ so that old browsers that do not support JavaScript treat information within the Script tag as comments. Writing on the page
example-writing on the page
Result is shown in Fig. 2 below.
Fig. 2
Here, ‘document’ is a browser object and ‘write’ is its function which is used to write text on the page. Browser objects are loaded by a JavaScript capable browser to provide access to the web page and the HTML elements it contains. These objects are used to update and interact with the loaded web page.
Operators in java script Mathematical operators ‘+’ For addition of two values ‘-‘ for subtraction of two values ‘*’ for multiplication ‘/’ for division ‘%’ modulus (for calculating the remainder) ‘++’ for increment ‘--‘ for decrement Logical operators ‘&&’ for logical and ‘||’ for logical or ‘!’ for logical not
Comparison operators ‘==’ for Equal ‘!=’ for not equal ‘< ‘ for Less than ‘<=’ for less than equal ‘>’ for Greater than ‘>=’ for Greater than equal
Functions in javascript
A variable in JavaScript can be defined using the keyword ‘var’ and a function by the Keyword ‘function. A function can be defined in the following format: function myfunction() { // some code } Here, ‘myfunction’ is the name of the function. Creating a calculator in JavaScript
My Simple Calculator
Add and Subtract Calculator
Add Subtract Calculator
First Number:
Second Number:
Result:
Result is shown in Fig. 5 below in a text box, if you type nos. 125 and 66 in the two text boxes, respectively, and click ‘Add them!!’.
Fig. 5