Client
Side Scripting (JavaScript)
SOP 1: Create a
JavaScript program for the following using appropriate variables, JavaScript
inbuilt functions and control structures.
·
To accept integer and display the result by
multiplying it with 3.
<!DOCTYPE
html>
<html>
<head>
<title>SOP
1_1</title>
</head>
<body>
<script
type="text/javascript">
function
result()
{
var num,res=0;
num=prompt("Enter
the number");
res=num*3;
document.write("Multiplication
of "+num+" with 3 is : "+res);
}
</script>
</body>
</html>
·
To accept two integers and display larger number of
them.
<!DOCTYPE
html>
<html>
<head>
<title>SOP1_2</title>
</head>
<body>
<script
type="text/javascript">
var num1,num2;
num1=prompt("Enter
first number");
num2=prompt("Enter
Second number");
if(num1>num2)
{
alert("Num1
is greater than num2");
}
else
{
alert("num2
is greater than num1");
}
</script>
</body>
</html>
·
To check whether, user entered number is positive or
negative.
<!DOCTYPE
html>
<html>
<head>
<title>SOP1_3</title>
</head>
<body>
<script
type="text/javascript">
var
num=prompt("Enter your number to check");
if(num>0)
{
alert("Number
is Positive");
}
else
{
alert("Number
is Negative");
}
</script>
</body>
</html>
SOP 2: Create a
JavaScript program for the following using appropriate variables, JavaScript
inbuilt functions and control structures.
·
To accept two positive or negative numbers and check
whether they are equal or not.
<!DOCTYPE
html>
<html>
<head>
<title>SOP2_1</title>
</head>
<body>
<script
type="text/javascript">
var num1,num2;
num1=prompt("Enter
first integer");
num2=prompt("Enter
second integer");
if(num1==num2)
{
alert("Both
numbers are equal");
}
else
{
alert("Both
number are not equal");
}
</script>
</body>
</html>
·
To accept number and display square of it.
<!DOCTYPE
html>
<html>
<head>
<title>SOP2_2</title>
</head>
<body>
<script
type="text/javascript">
var num,result;
num=prompt("Enter
the number");
result=num*num;
alert("Square
of "+num+" is : "+result);
</script>
</body>
</html>
·
To check whether the accepted integer is multiple of
3 or multiple of 7.
<!DOCTYPE
html>
<html>
<head>
<title>SOP3_3</title>
</head>
<body>
<script
type="text/javascript">
var
num=prompt("Enter the number to check");
if(num%3==0
&& num%7==0)
{
alert(num+"
is multiple of 3 and 7");
}
else
if(num%3==0)
{
alert(num+"
is multiple of 3")
}
else
if(num%7==0)
{
alert(num+"
is multiple of 7")
}
else
{
alert(num+"
is not multiple of 3 and 7");
}
</script>
</body>
</html>
SOP 3: Create a
JavaScript program for the following using appropriate variables, JavaScript
inbuilt functions and control structures.
·
To accept string and calculate its length.
<!DOCTYPE
html>
<html>
<head>
<title>SOP3_1</title>
</head>
<body>
<script
type="text/javascript">
var
str=prompt("Enter string to calculate length");
var len;
alert("Length
of string is :- "+str.length);
</script>
</body>
</html>
·
To accept string and display it into lowercase and
uppercase.
<!DOCTYPE
html>
<html>
<head>
<title>SOP3_2</title>
</head>
<body>
<script
type="text/javascript">
var
str,strlwr,strupr;
str=prompt("Enter
your string");
strlwr=str.toLowerCase();
strupr=str.toUpperCase();
alert("String
in upper case :- "+strupr);
alert("String
in lower case :-"+strlwr);
</script>
</body>
</html>
·
To check whether the length of string is 4 or
greater.
<!DOCTYPE
html>
<html>
<head>
<title>SOP3_3</title>
</head>
<body>
<script
type="text/javascript">
var str,len;
str=prompt("Enter
your string");
len=str.length;
if(len==4)
{
alert("String
length is equal to 4");
}
else
if(len>4)
{
alert("String
length is greater than 4")
}
else
{
alert("String
length is less than 4");
}
</script>
</body>
</html>
SOP 4: Create a
JavaScript program for the following using appropriate variables, JavaScript
inbuilt functions and control structures.
·
To accept number and validate if the given value is
a number or not by clicking on the button.
<!DOCTYPE
html>
<html>
<head>
<title>SOP4_1</title>
</head>
<body>
<form
name="f1">
Enter Value
:<input type="text" name="t1"> <br><br>
<input
type="button" value="Check"
onclick="validate()">
</form>
<script
type="text/javascript">
function
validate()
{
var
num=document.f1.t1.value;
if(num>=0)
{
alert("Entered
value is number");
}
else
{
alert("Entered
value is not a number");
}
}
</script>
</body>
</html>
·
To calculate addition and division of two numbers.
<!DOCTYPE
html>
<html>
<head>
<title>SOP4_2</title>
</head>
<body>
<form
name="f1">
Enter Number
1:<input type="text" name="t1"><br><br>
Enter Number
2:<input type="text" name="t2"><br><br>
<input
type="button" value="Addition"
onclick="add()">
<input
type="button" value="Divide" onclick="div()">
</form>
<script
type="text/javascript">
var a,b,c=0,d=0;
function add()
{
a=parseFloat(document.f1.t1.value);
b=parseFloat(document.f1.t2.value);
c=a+b;
alert("Addition
of "+a+" and "+b+" is : "+c);
}
function div()
{
a=parseFloat(document.f1.t1.value);
b=parseFloat(document.f1.t2.value);
d=a/b;
alert("Division
of "+a+" and "+b+" is : "+d);
}
</script>
</body>
</html>
0 comments:
Post a Comment