Practical No.1: Write simple JavaScript with HTML for arithmetic expression evaluation and message printing.

 

What is HTML?

·       HTML stands for Hypertext markup language

·       HTML is the standard markup language for creating Web pages.

·       HTML describes the structure of a Web page.

·       HTML consists of series of elements and tags represent these elements.

What is Javascript?

·       Javascript is a dynamic computer programming language.It is lightweight and commonly used web pages of client side script to interact with user and make a dyanamic page.

·       Javascript was first known as Live script and Netscape introduced it in 1995.

Features of JavaScript:

1.     Light weighted

2.    Case sensitive.

3.    Control statement

4.    Looping statement

5.    Client side technology

6.    Event handling

7.     Interpreter based

8.    In build function

Uses of Javascript:

1.     Client side validation

2.    Dynamic dropdown menus

3.    Open and close new windows

4.    Manipulated HTML layers

5.    Enhance the interfaces HTML

6.    Animated elements on a page

7.     Fixed browser problems

How to write Javascript document?

·       The Javascript can be directly embedded within the HTML,document or it can be stored as external files.

·       Syntax:

 

<script ...>

JavaScript code


</script>

 

·       The script has takes two important attributes:

·       Language

·       Type

Sample Program: Hello World…

<html>

<body>

<script language=”Javascript” type=”text/javascript”>

<!—

Document.write (“Hello world”);

</script>

</body>

</html>

Explanation:

1.     Document.write: This statement is used to display desired message on webbrowser.

2.    Comments in java:

3.    The // is a single line comments

4.    The /*…*/ can be used as multi line comments

5.    The XHTML <!--> and <--> is also known as javascript

Arithmetic Operators:

1.     Addition (+):-This operator is used to add two operands.

2.    Subtraction (-):-This operator is used to subtract two operands.

3.    Multiplication (*):-This operator is used to multiple two operand.

4.    Division (/):-This operator is used to divide two operands.

5.    Modulus (%):-This operator is used to check the Remainder.

6.    Increment (++):-This operator is used to increment operand by 1.

7.     Decrement (--):-This operator is used to decrement operand by1.

Conclusion: We understand that how to write javascript with HTML for arithmetic expression evaluation and message printing.


Practical No.1: Write simple JavaScript with HTML for arithmetic expression evaluation and message printing.

1]

            <html>

<body>

<script type=""text/javascript>

var a=10; 

var b=20;

document.write("<b>Addition of a and b:- </b>"); 

var c=a+b;

document.write(c); document.write("</br></br><b>Substraction of a and b:- </b>"); 

var d=a-b;

document.write(d); 

document.write("</br></br><b>Multiplication of a and b:- </b>"); var e=a*b;

document.write(e); document.write("</br></br><b>Division of a and b:- </b>"); 

var f=a/b;

document.write(f);

document.write("</br></br><b>Module of a and b:- </b>"); 

var g=a%b;

document.write(g); 

document.write("</br></br><b>Decrement of a:- </b>"); 

var h=a--;

document.write(h); document.write("</br></br><b>Increment of a:- </b>"); 

var i=a++;

document.write(i);

</script>

</body>

</html>


Output:


2]

<html>

<body>

<script>

var a = 10; var b = 20;

document.write("<b>Addition of a(" + a + ") and b(" + b + ") :- </b>");

var c = a + b; 

document.write(c);

document.write("</br></br><b>Substraction of a(" + a + ") and b(" + b + ") :- </b>");

var d = a - b; document.write(d);

document.write("</br></br><b>Multiplication of a("+ a + ") and b(" + b + ") :- </b>"); var e = a * b; document.write(e);

document.write("</br></br><b>Division of a(" + a + ") and b(" + b + ") :- </b>");

var f = a / b; document.write(f);

document.write("</br></br><b>Module of a(" + a + ") and b(" + b + ") :- </b>"); var g = a % b; document.write(g);

document.write("</br></br><b>Square of a(" + a + "):- </b>");

var h = a * a; document.write(h);

document.write("</br></br><b>Cube of a(" + a + ") :-</b>");

var i = a * a * a;

document.write(i);

</script>

</body>

</html>


Output:

Comments

  1. Thank you
    Nice answers Solutions and all points clear and clean

    ReplyDelete

Post a Comment