0% found this document useful (0 votes)
5 views11 pages

ujwal java

The document is a lab report detailing various examples of JavaScript code and their outputs. Each example demonstrates different programming concepts such as arithmetic operations, logical operators, functions, and control structures. The report is prepared by Ujwal Shrestha for MR Navraj Adhikari, dated 2081/04/24.

Uploaded by

kdhakal3210
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views11 pages

ujwal java

The document is a lab report detailing various examples of JavaScript code and their outputs. Each example demonstrates different programming concepts such as arithmetic operations, logical operators, functions, and control structures. The report is prepared by Ujwal Shrestha for MR Navraj Adhikari, dated 2081/04/24.

Uploaded by

kdhakal3210
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Lab Report

SHREE
POKHAR
IYA
SECOND
ARY
SCHOOL

Report Title: Lab Report


Date of Visit: 2081/04/24
Prepared By: Ujwal Shrestha
Prepared For: MR Navraj Adhikari
ADDING JAVASCRIPT TO HTML PAGE
EXAMPLE NUMBER=1
<HTML>
<BODY>
<P>comparison and addition</P>
<script type="text/javascript">
var a = 9;
var b = 75;
document.write("a=9 <br> b=75");
document.write("<br>a+b=");
document.write(a + b);
document.write("<br>a<b:");
document.write(a < b);
document.write("<br>a<=b:");
document.write(a <= b);
document.write("<br>a>b:");
document.write(a > b);
document.write("<br>a>=b:");
document.write(a >= b);
document.write("<br>a==b:");
document.write(a == b);
document.write("<br>a!=b:");
document.write(a != b);
</script>
</BODY>

</HTML> OUTPUT: comparison and addition:


a=9,b=75,a+b=84,a<b:true,a<=b:true,a>b:false,a>=b:false,a==b:false,a!=b:true</b:true
EXAMPLE NUMBER=2
<html>
<body>
<h1>CAR DEITAIL</h1>
<SCRIPT>
var car={
make:"BMW",
model:"RAV4",
year:2020,
number:"ba29hd-2019",
display:function(){
return this.make+"--"+this.model+"--"+this.year+"--"+this.number; }};
document.write(car.display());
</SCRIPT>
</body>

</html> OUTPUT:CAR DEITAL: BMW--RAV4--2020--ba29hd-2019


EXAMPLE NUMBER=3
<html>
<head>
<title>Web server</title>
</head>
<body>
<script language="javascript" type="text/javascript">
var x = 30;
document.write("The value of x = " + (20 + x));
</script>
</body>

</html> OUTPUT: The value of x = 50


EXAMPLE NUMBER=4
<html>
<body><p>Example of logical operators</p></body>
<script type="text/javascript">
var a= true;
var b= false;
document.write("<br>a=true <br>b=false:");
document.write("<br>a&&b:");
document.write(a&&b);
document.write("<br>a||b:");
document.write(a||b);
document.write("<br>!a:");
document.write(!a);
document.write("<Br> !b:");
document.write(!b);
</script>

</html> OUTPUT: Example of logical operators a=true, b=false:, a&&b:false,a||b:true ,!


a:false, !b:true
EXAMPLE NUMBER=5
<html>
<body>
<script type="text/javascript">
var day=prompt("enter a number=");
switch(day)
{
case "1": document.write("<br>SUNDAY:<h1>PHYSICS,CHEMISTRY, MATH</h1>");
break;
case "2": document.write("<br>MONDAY<H2>PHYSICS,CHEMISTRY,");
break;
case "3": document.write("<br>TUESDAY");
break;
case "4": document.write("<br>WEDNESDAY");
break;
case "5": document.write("<br> THURSDAY");
break;
case "6": document.write("<br> FRIDAY");
break;
case "7": document.write("<br> SATURDAY");
break;
case "8": document.write("<br>happy day");
break;
case "9": document.write("<br>School day");
break;
default: document.write("<br> invaled day");
}
</script>
</body>

</html> OUTPUT: Enter any number 1 to 9=if 1= SUNDAY: PHYSICS,CHEMISTRY,


MATH

EXAMPLE NUMBER=6
<!DOCTYPE html>
<html>
<head>
<title>First java script</title>
<body>
<script type="text/javascript">
document.write("You are Programmer.");
alert("Thanks for visiting my website.");
confirm("Please provide Accurate code");
prompt("enter your code:");
</script>
</body>
</head>

</html> OUTPUT: You are Programmer


EXAMPLE NUMBER=7
<!DOCTYPE html>
<html>
<head>
<title> Hello world</title>
</head>
<body>
<script type="text/javascript">
document.write("single line command");//this is an example of single line command
document.write("<br>");
document.write("multi line command");/* this is multiple line command.*/
</script>
/body>
</html> OUTPUT: single line command and multiple line command
EXAMPLE NUMBER=8
<html>
<body>
<script type="text/javascript">
var count=1;
var m;
do {
m=count*250
document.write("<br>"+m);
count++;
}while(count<=10);
</script>
</body>

</html> OUTPUT: 250,500,750,1000,1250,1500,1750,2000,2250,2500


EXAMPLE NUMBER=9
<!DOCTYPE html>
<html>
<head>
<title> For arthematic operation</title>
</head>
<body>
<script type="text/javascript">
var a = 25;
var b = 40;
var result;
document.write("a= 25 <br> b=10" );
result=a+b;
document.write("<br> a+b="+result);
result=a-b;
document.write("<br> a-b="+result);
result=a*b;
document.write("<br> a*b="+result);
result=a/b;
document.write("<br> a/b="+result);
result=a%b;
document.write("<br> a%b="+result);
a++;
document.write("<br>Example of a++="+a);
b--;
document.write("<br>Example of b--="+b);
</script>
</body>

</html> OUTPUT: a= 25, b=10, a+b=65, a-b=-15 ,a*b=1000 ,a/b=0.625, a%b=25, Example
of a++=26 ,Example of b--=39
EXAMPLE NUMBER=10
<html>
<body>
<script type="text/javascript">
var n=prompt("enter a number=");
if(n%2==1)
document.write("number is odd" +n);
else
document.write("number is even" +n);
</script>
</body>

</html> OUTPUT: Enter any number= If the remainder is “0,” then it is an even number; if
the remainder is 1, then it is an odd number.
EXAMPLE NUMBER=11
<html>
<body>
<script type="text/javascript">
var count=1;
var f=1;
var i,n;
n=prompt("enter the number to calculate=")
for(i=1;i<=n;i++)
f=f*i;
document.write("<br> The fractional is="+f);
</script>
</body>
</html> OUTPUT: Enter the any number to calculate=If no is 4 then value is 24
EXAMPLE NUMBER=12
<html>
<body>
<script type="text/javascript">
var a =10;
var b =23;
var max;
document.write("<br>a=10<br>b=23");
max=(a>b)?a:b;
document.write("<br>the maximum numberis=");
document.write(max);
</script>
</body>

</html> OUTPUT :a=10,b=23 : The maximum numberis=23


EXAMPLE NUMBER=13
<html>
<body>
<h2>example of local functios:area of rectangle</h2>
<script type="text/javascript">
function area(l,b)
{
return l*b;
}
var a =area(9,8908);
document.write("<br>length=9<br>breadth=8908<br><br>area="+a);
</script>
</body>

</html>OUTPUT : example of local functios:area of rectangle length=9 breadth=8908


area=80172
EXAMPLE NUMBER=14
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
var a = 12;
var b = 89;
var c = 23;
document.write("<br>a = 12<br>b = 89<br>c = 23<br>");
if (a > b && a > c) {
document.write("Greater number is = " + a);
} else if (b > c) {
document.write("Greater number is = " + b);
} else {
document.write("Greater number is = " + c);
}
</script>
</body>

</html> OUTPUT: a = 12,b = 89,c = 23:Greater number is = 89


EXAMPLE NUMBER=15
<html>
<body>
<script type="text/javascript">
var counter=1;
while(counter<=10)
{
document.write("<br>"+counter);
counter++;
}
</script>
</body>

</html> OUTPUT: 1,2,3,4,5,6,7,8,9,10


EXAMPLE NUMBER=16
<html>
<body>
<p id="eg"></p>
<script type="text/javascript">
document.getElementById("eg").innerHTML="hello world";
</script>
</body>

</html> OUTPUT: hello world


EXAMPLE NUMBER=17
<html>
<body>
<h3>
CAR INFORATION
</h3>
<script type="text/javascript">
var car={
make:"TOYOTA",
model:"RAV44",
year:2023,
number:"BA23PA-2021"
};
document.write(car.make+"--"+car.model+"--"+car.year+"--"+car.number);
</script>
</body>

</html> OUTPUT: CAR INFORATION :TOYOTA--RAV44--2023--BA23PA-2021


EXAMPLE NUMBER=18
<html>
<head>
<title>Hello world </title>
</head>
<body>
<script type="text/javascript">
document.write("hello world");
</script>
</body>

</html> OUTPUT=hello world


EXAMPLE NUMBER=19
<html>
<head>
<script type="text/javascript">
function area(l,b)
{return l*b;}
</script>
</head>
<body>
<h2>example of global function:area of retangle </h2>
<script type="text/javascript">
var a=area(5,4);
document.write("<br>length=5<br>breadth=4<br><br>area="+a);
</script>
</body>

</html> OUTPUT: Example of global function:area of retangle =length=5,breadth=4


area=20
EXAMPLE NUMBER=20
<html>
<body>
<script type="text/javascript">
var a =10;
document.write("<br>value of a =>"+a);
a+=5;
document.write("<br>value of a +=>"+a);
a-=5;
document.write("<br>value of a -=>"+a);
a*=5;
document.write("<br>value of a *=>"+a);
a/=5;
document.write("<br>value of a /=>"+a);
a%=5;
document.write("<br>value of a %=>"+a);
</script>
</body>

</html> OUTPUT: value of a =>10, value of a +=>15 ,value of a -=>10, value of a *=>50,
value of a /=>10, value of a %=>0

You might also like