Professional Documents
Culture Documents
Hi Yusika 2
Hi Yusika 2
Hi Yusika 2
Source Code:
<html>
<head>
<title>Arithmetic Operation</title>
</head>
<body> <script>
var x=50,y=10,a,s,m,d;
a=x+y;
s=x-y;
m=x*y;
d=x/y;
document.write("Addition is "+a);
document.write("<br>");
document.write("Subtraction is "+s);
document.write("<br>");
document.write("Multiplication is "+m);
document.write("<br>");
document.write("Division is "+d);
</script>
</body>
</html>
OUTPUT:
Program No:2
Program to demonstrate assignment operation in javascript.
Source Code:
<html>
<head>
<title>Assignment Operator</title>
</head>
<body>
<h3>Assignment Operator</h3>
<script> var
a=5,b=6,c=7,d=8,e=9;
a+=5;
b-=5;
c*=2;
d/=4;
e%=5;
document.write("<br>");
document.write("<br>");
document.write("c=7 becomes "+c);
document.write("<br>");
document.write("<br>");
</script>
</body>
</html>:
OUTPUT:
Program No:3
Program to demonstrate comparison and logical operator in javascript.
Source Code:
<html>
<head>
<title>Comparison and Logical Operator</title>
</head>
<body>
<h3>Comparison and Logical Operator</h3>
<script>
var a=5,b=6;
document.write(a+ " > " +b , " ", "is", " " +(a>b));
document.write("<br>");
document.write(a+ " < "+b ," ", "is", " " +(a<b));
document.write("<br>");
document.write(a+ " == " +b ," ", "is", " " +(a==b));
document.write("<br>");
document.write(a+ " > " +b ," ", "is", " " +(a==b&&a!=b));
document.write("<br>");
</script>
</body>
</html>
OUTPUT:
\
Program No:4
\Program to demonstrate string operator in javascript
Source Code:
<html>
<head>
<title>String Operator</title>
</head>
<body>
<h3>String Operator</h3>
<script>
var a="Yusika",b="shrestha";
document.write(a+" "+b);
</script>
</body>
</html>
OUTPUT:
Program No:5
Program to demonstrate type of operator in javascript.
Source Code:
<html>
<head>
<title>Type of Operator</title>
</head>
<body>
<h3>Type of Operator</h3>
<script>
var a="Yusika";
var b=30;
var c=false;
document.write("<br>");
document.write("<br>");
</script>
</body>
</html>
OUTPUT:
Program No:6
Program to demonstrate calling function in javascript.
Source Code:
<head>
<title>Calling function</title>
</head>
<body>
<h3>Calling Function</h3>
<script>
function hello()
function hello1(hisname)
function sum(a,b)
return(a+b);
hello();
hello1("Yusika");
var s=sum(10,5);
</script
</body>
</html>
OUTPUT:
Program No:7
Program to demonstrate arrow function in javascript.
Source Code:
<html>
<head>
<title>Arrow function</title>
</head>
<body>
<h3>Arrow Function</h3>
<script>
let add=(x,y)=>{
return x+y;
}
alert(add(3,4));
</script>
</body>
</html>
OUTPUT:
Program No:8
Program to demonstrate if else in javascript.
Source Code:
<html>
<head>
<title>If Else</title>
</head>
<body>
<h3>If Else</h3><br>
<p>Enter age:<input type="text" id="age"
onchange="check()"></input></p>
<script>
function check()
{
var
ag=document.getElementById("age").value;
ag=parseInt(ag); if(Number.isInteger(ag)){
if(ag<13){
document.write("You are child.<br>");
}
else if(ag>=13&&ag<20){
document.write("You are Teen.<br>");
}
else if(ag>=20&&ag<=50){
document.write("You are adult.<br>");
}
else if(ag>50){
document.write("You are old.<br>");
}
}
}
</script>
</body>
</html>
OUTPUT:
Program No:9
Program to demonstrate loop in javascript.
Source Code:
<html>
<head>
<title>Loop</title>
</head>
<body>
<h3>Loop</h3>
<script>
var i;
for(i=1;i<10;i++)
{
document.write("Hello"+i);
document.write("<br>");
}
</script> <script>
document.write("<br>")
var n=1;
while(n<=10){
document.write("<br>")
document.write(n);
n++;
}
</script>
<br><br>
<script> var
p=0; do{
p+=1; }
while(p<=7)
document.write("Sum= " +p);
</script>
</body>
</html>
OUTPUT:
Program No:10
Program to demonstrate switch in javascript.
Source Code:
<html>
<head>
<title>Switch</title>
</head>
<body>
<h3>Switch</h3>
<script> var
sub="computer";
switch(sub)
{ case
"english":
case "nepali":
document.write("English and Nepali are on
Monday.<br>"); break; case "math":
document.write("Mathematics is on
Tuesday.<br>"); break; case
"computer":
document.write("Computer is on
Wednesday.<br>"); break; case "physics":
case "chemistry":
document.write("Physics and Chemistry are on Thrusday and
Friday.<br>"); break; default:
document.write("No other subjects.");
}
</script>
</body>
</html>
OUTPUT:
Program No:11
Program to create object in javascript by object lateral.
Source Code:
<html>
<body>
<h3>Create object by object lateral</h3>
<script>
emp=(id:1,name:"Yusika",salary:40000);
document.write(emp.id+" "+emp.name, " "+emp.salary);
</script>
</body>
</html>
OUTPUT:
1. Yusika40000
Program No:12
Program to create an instance of object directly in javascript.
Source Code:
<html>
<head></head>
<body>
<h3>Creating an instance of object directly</h3>
<script> var emp=new Object(); emp.id=1;
emp.name=" Yusika"; emp.salary=10000;
document.write(emp.id+" "+emp.name, "
"+emp.salary);
</script>
</body>
</html>
OUTPUT:
Source Code:
<html>
<head> <script>
function sayHello() {
alert("Hello World")
</script>
</head>
<body>
<form>
</form>
</body>
</html>
OUTPUT:
Program No:14
Program to demonstrate on submit event in javascript.
Scode code:
<html>
<head> <script>
function validation() {
.......
</script>
</head>
<body>
.......
</form>
</body> </html>
OUTPUT:
Program No:15
Program on mouse over event in javascript.
Scode code:
<head> <script>
function over()
document.write("Mouse Over")
function over(){
document.write("Mouse Out")
</script>
</head>
<body>
</div>
</body>
</html>
OUTPUT:
Program No:16
Program validation of form in javascript.
Source Code:
<html>
<head>
<title>Form Validation</title>
<!--
//-->
</script>
</head>
<body>
<tr>
</tr>
<tr>
</tr>
<tr>
<td align = "right">Zip Code</td>
</tr>
<tr>
<td>
</select>
</td>
</tr>
<tr>
</tr>
</table>
</form>
</body>
</html>
OUTPUT: