Hi Yusika 2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 27

Program No:1

Program to demonstrate arithmetic operators in javascript.

Source Code:

//Program to demonstrate arithmetic operators in javascript.

<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:

//Program to demonstrate assignment operation in javascript..

<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("a=5 becomes "+a);

document.write("b=6 becomes "+b);

document.write("<br>");

document.write("<br>");
document.write("c=7 becomes "+c);

document.write("<br>");

document.write("d=8 becomes "+d);

document.write("<br>");

document.write("e=9 becomes "+e);

</script>

</body>

</html>:

OUTPUT:
Program No:3
Program to demonstrate comparison and logical operator in javascript.

Source Code:

//Program to demonstrate comparison and logical operator in javascript.

<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:

//Program to demonstrate string operator in javascript.

<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:

//Program to demonstrate type of operator in javascript.

<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("Data type of " +a ," is " +typeof(a) , ".");

document.write("<br>");

document.write("Data type of " +b ," is " +typeof(b) , ".");

document.write("<br>");

document.write("Data type of " +c ," is " +typeof(c) , ".");

</script>

</body>

</html>
OUTPUT:
Program No:6
Program to demonstrate calling function in javascript.

Source Code:

//Program to demonstrate calling function in javascript.


<html>

<head>

<title>Calling function</title>

</head>

<body>

<h3>Calling Function</h3>

<script>

function hello()

document.write("Hello everyone, welcome to JavaScript<br><br>");

function hello1(hisname)

document.write("Hello " +hisname+ " welcome to JavaScript <br><br>");

function sum(a,b)

return(a+b);

hello();

hello1("Yusika");

var s=sum(10,5);

document.write("Sum= " +s);

</script

</body>

</html>
OUTPUT:
Program No:7
Program to demonstrate arrow function in javascript.

Source Code:

//Program to demonstrate arrow function in javascript.

<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:

//Program to demonstrate if else in javascript.

<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:

//Program to demonstrate if loop in javascript.

<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:

//Program to demonstrate switch in javascript.

<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:

// Program to create object in javascript by object lateral.

<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:

// Program to create an instance of object directly in javascript.

<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:

1. Yusika Shrestha 10000


Program No:13
Program to demonstrate onclick event in javascript.

Source Code:

// Program to demonstrate onclick event in javascript.

<html>

<head> <script>

function sayHello() {

alert("Hello World")

</script>

</head>

<body>

<p>Click the following button and see the result</p>

<form>

<input type="button" onclick = "sayHello()" value = "Say Hello" />

</form>

</body>

</html>

OUTPUT:
Program No:14
Program to demonstrate on submit event in javascript.

Scode code:

//Program to demonstrate onsubmit event in javascript.

<html>

<head> <script>

function validation() {

all validation goes here

.......

return either true or false

</script>

</head>

<body>

<form method = "POST" action="t.cgi" onsubmit = "return validate()">

.......

<input type="submit" value = "Submit" />

</form>

</body> </html>

OUTPUT:
Program No:15
Program on mouse over event in javascript.

Scode code:

//Program on mouse over event in javascript


<html>

<head> <script>

function over()

document.write("Mouse Over")

function over(){

document.write("Mouse Out")

</script>

</head>

<body>

<p>Bring your mouse inside the division to see the result</p>

<div onmouseover="over()" onmouseout="out">

<h2>This is inside the division</h2>

</div>

</body>

</html>

OUTPUT:
Program No:16
Program validation of form in javascript.

Source Code:

//Program validation of form in javascript

<html>

<head>

<title>Form Validation</title>

<script type = "text/javascript">

<!--

// Form validation code will come here.

//-->

</script>

</head>

<body>

<form action = "/cgi-bin/test.cgi" name = "myForm" onsubmit = "return(validate());">

<table cellspacing = "2" cellpadding = "2" border = "1">

<tr>

<td align = "right">Name</td>

<td><input type = "text" name = "Name" /></td>

</tr>

<tr>

<td align = "right">EMail</td>

<td><input type = "text" name = "EMail" /></td>

</tr>

<tr>
<td align = "right">Zip Code</td>

<td><input type = "text" name = "Zip" /></td>

</tr>

<tr>

<td align = "right">Country</td>

<td>

<select name = "Country">

<option value = "-1" selected>[choose yours]</option>

<option value = "1">USA</option>

<option value = "2">UK</option>

<option value = "3">NEPAL</option>

</select>

</td>

</tr>

<tr>

<td align = "right"></td>

<td><input type = "submit" value = "Submit" /></td>

</tr>

</table>

</form>

</body>

</html>

OUTPUT:

You might also like