A Laboratory Manual for
Client Side Scripting
     Language
            (22519)
   Semester –V
                  (CM)
   Maharashtra State Board of Technical Education, Mumbai.
                              Maharashtra State
                     Board of Technical Education
                                      Certificate
This is to certify that Mr./Ms.
……………………………………………………………………………… Roll No……………………..of
Fifth Semester of Diploma in Computer Technology of
Institute,………………………………………………………………………………………………………
(Code : ……………………..) has completed the term work satisfactorily in course
Client Side Scripting languages (22519) for the academic year ………………… to
………………….. as Prescribed in the curriculum.
Place: …………………………………                                    Enrollment No: ………………………………..
Date: ………………………………….                                    Exam. Seat No: …………………………………
Subject Teacher                   Head of Department                    Principal
                                  Seal of Institution
Client Side Scripting Languages (22519)
Practical No 1: Write simple JavaScript with HTML for arithmetic expression
evaluation and message printing.
What is JavaScript?
            –   It is designed to add interactivity to HTML pages
            –   It is a scripting language (a lightweight programming language)
            –   It is an interpreted language (it executes without preliminary compilation)
            –   Usually embedded directly into HTML pages
            –   And, Java and JavaScript are different
What can a JavaScript Do?
            – JavaScript gives HTML designers a programming tool:
                    o simple syntax
            – JavaScript can put dynamic text into an HTML page
            –   JavaScript can react to events
            – JavaScript can read and write HTML elements
            –   JavaScript can be used to validate data
            –   JavaScript can be used to detect the visitor’s browser
            –   JavaScript can be used to create cookies
                    o Store and retrieve information on the visitor’s computer
JavaScript How To
    – The HTML <script> tag is used to insert a JavaScript into an HTML page
    <script type=“text/javascript”>
    document. write(“Hello World!”)
    </script>
    –   Ending statements with a semicolon?
            o Optional; required when you want to put multiple statements on a single line
JavaScript can be inserted within the head, the body, or use external JavaScript file
Maharashtra State board of Education
   Client Side Scripting Languages (22519)
   How to handle older browsers?
   <script type=“text/javascript”>
   <!—
   document.write(“Hello World!”)
   // -->
   </script>
   JavaScript can "display" data in different ways:
            Writing into an HTML element, using innerHTML.
   To access an HTML element, JavaScript can use the document.getElementById(id) method.
   The id attribute defines the HTML element. The innerHTML property defines the HTML content.
            Writing into the HTML output using document.write().
            Writing into an alert box, using window.alert().
            Writing into the browser console, using console.log().
   JavaScript Variables
            In a programming language, variables are used to store data values.
            JavaScript uses the var keyword to declare variables.
            An equal sign is used to assign values to variables.
   JavaScript Arithmetic Operators
            Arithmetic operators are used to perform arithmetic on numbers:
             Operator        Description
             +              Addition
             -              Subtraction
             *              Multiplication
             /              Division
             %              Modulus (Remainder)
             ++             Increment
             --             Decrement
Maharashtra State board of Education
Client Side Scripting Languages (22519)
1.Simple Java Script Program
<html>
<head>
   <title> Simple Javascript code </title>
</head>
<script language="text/JavaScript">
document. write("Hello World!");
alert("Error");
</script>
</html>
Maharashtra State board of Education
Client Side Scripting Languages (22519)
Output:
Maharashtra State board of Education
   Client Side Scripting Languages (22519)
   2.Perform Arithmetic operation of Two Numbers
   <html>
   <head>
      <title>Arithmetic Example </title>
   </head>
   <script language="text/JavaScript">
   var a = 10;
   var b = 20;
   var sum = a+b;
   var sub = a-b;
   var mul = a*b;
   var div = a/b;
   document.write(“Addition of two numbers are: ”+sum);
   document.write(“<br/>Subtraction of two numbers are: ”+sub);
   document.write(“<br/>Multiplication of two numbers are: ”+mul);
   document.write(“<br/>Division of two numbers are: ”+div);
   </script>
   </html>
Maharashtra State board of Education
Client Side Scripting Languages (22519)
Output:
   Maharashtra State board of Education
Client Side Scripting Languages (22519)
Questions:
1. Which company developed JavaScript?
-> Brendan Eich, a software engineer at Netscape Communications, developed JavaScript in 1995.
2. What are JavaScript Data Types?
-> Primitive Data Types:
    Number: Represents numerical values, including integers and floating-point numbers.
    String: Represents textual data, enclosed in single or double quotes or backticks.
    Boolean: Represents logical values, either true or false.
    Undefined: Represents a variable that has been declared but not assigned a value.
    Null: Represents the intentional absence of any object value.
3. How to declare variable in Javascript?
-> Variables are Containers for Storing Data
JavaScript Variables can be declared in 4 ways:
    Automatically
    Using var
    Using let
    Using const
4. What are arithmetical operators?
-> Arithmetic operators in JavaScript are symbols used to perform
basic mathematical calculations. Here are the most common ones:
    Addition (+): Adds two numbers together.
    Subtraction (-): Subtracts one number from another.
    Multiplication (``)*: Multiplies two numbers.
    Division (/): Divides one number by another.
    Modulus (%): Returns the remainder after division.
    Increment (++): Increases the value of a variable by 1.
    Decrement (--): Decreases the value of a variable by 1.
                                               Marks Obtained                Dated Signed of
                                                                                teacher
                                      Process       Product      Total(50)
                                     Related(35)   Related(15)
Maharashtra State board of Education