You are on page 1of 4

COMPUTER ENGINEERING

DEPARTMENT

Subject: Client Side Scripting Subject Code:22519


th
Semester: 5 Course: Computer Engineering
Laboratory No: L001B Name of Subject Teacher: Prof Pokharkar M. S.
Name of Student: Roll Id:

Experiment No: 1
Title of Experiment Write simple Javascript with HTML for arithmetic expression evaluation and
message printing.

Theory: JavaScript is the programming language of HTML and the Web.

JavaScript Arithmetic Operators

Arithmetic operators perform arithmetic on numbers (literals or


variables).

Operator Description

+ Addition

- Subtraction

* Multiplication

** Exponentiation

/ Division

% Modulus (Remainder)

Page | 1
++ Increment

A typical arithmetic operation operates on two numbers.

The two numbers can be literals:

Operators and Operands

The numbers (in an arithmetic operation) are called operands.

The operation (to be performed between the two operands) is defined by an operator.

Syntax:-

var x = 5; // assign the value 5 to x


var y = 2; // assign the value 2 to y
var z = x + y; // assign the value 7 to z (x + y)

Example:-

<p id="demo"></p>

<script>

var x = 5;

var y = 2;

var z = x + y;

document.getElementById("demo").innerHTML = z;

</script>

Program:

<html>
<head>
<title>TODO supply a title</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type="text/JavaScript" src="arithematic.js">
</script>
</head>
<body>
</body>
</html>

Page | 2
Js file:-
var a=10 , b=20;
function add()
{
var c;
c=a+b;
document.write("Addition is:"+c);
}

function sub()
{
var k;
k=a-b;
document.write("subtraction is:"+k);
}

function mul()
{
var o;
o=a*b;
document.write("multiplication is:"+o);
}

function div()
{
var m;
m=a/b;
document.write("Division is:"+c);
}

var i=parseInt(prompt("1.add<br>2.sub<br>3.mul<br>4.div"));
switch(i)
{
case 1:add();
break;
case 2:sub();
break;
case 3:mul();
break;
case 4:div();
break;
default:document.write("wrong choice ");break;
}

Page | 3
O
u
t

p
u
t
:

Grade and P1 (35) P2 (15) Total ( 50 M) Dated Sign


Dated
Signature of
Teacher

Page | 4

You might also like