0% found this document useful (0 votes)
7 views12 pages

JAVA SCRIPT PRACTICAL

Uploaded by

xaxajoyti273
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)
7 views12 pages

JAVA SCRIPT PRACTICAL

Uploaded by

xaxajoyti273
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/ 12

JavaScript Practical

EX1.PROGRAM PRINTING ONLY OUTPUT IN CONSOLE:

<html>

<head>

<title>my web page</title>

</head>

<body>

<h1> MY FIRST JS CODE </h1>

<script type="text/javascript">

console.log("Hello World!")

</script>

</body>

</html>

EX2. PROGRAM PRINTING OUTPUT IN BROWSER:

<html>

<head>

<title>my web page</title>

</head>

<body>

<h1> MY FIRST JS CODE </h1>

<script type="text/javascript">

alert("Hello World!")

</script>

</body>

</html>
EX3.PROGRAM USING ID

<html>

<html>

<body>

<h2>What Can JavaScript Do?</h2>

<p id="demo">JavaScript can change HTML content.</p>

<button type="button" onclick='document.getElementById("demo").innerHTML = "Hello


JavaScript!"'>Click Me!</button>

</body>

</html>

EX4.PROGRAM PRINTING VALUES

<html>

<head>

<title> my web page</title>

</head>

<body>

<script>

var a =34;

var b =56;

document.write("the sum of a&b is", a+b,"<br>")

document.write("the difference of a&b is", a-b,"<br>")

document.write("the product of a&b is", a*b,"<br>")

document.write("the division of a&b is", a/b,"<br>")


</script>

</body>

</html>

EX5.PROGRAM TAKING INPUTS FROM THE USER:

<html>

<head>

<title> my web page</title>

</head>

<body>

<script>

var a =prompt("num1:");

var b =prompt("num2");

document.write("the sum of a&b is", a+b,"<br>")

document.write("the difference of a&b is", a-b,"<br>")

document.write("the product of a&b is", a*b,"<br>")

document.write("the division of a&b is", a/b,"<br>")

</script>

</body>

</html>

EX6.PROGRAM ON EMPLOYEES:

<html>

<head>

<title> my web page</title>

</head>

<body background="1.jpg">
<font color="white">

<marquee bgcolor="blue">EMPLOYEE DETAILS</marquee>

<script>

var a =prompt("ENTER EMPLOYEE ID:");

var b =prompt("ENTER EMPLOYEE NAME");

var c =prompt("ENTER BASIC SALARY:");

var d =c*0.20;

document.write("THE EMPLOYEE ID IS :", a,"<br>")

document.write("THE EMPLOYEE NAME IS :", b,"<br>")

document.write("THE BASIC SALALRY :", c,"<br>")

document.write("THE DA IS: ", d,"<br>")

</script>

</font>

</body>

</html>

EX7.PROGRAM USING WHILE LOOP

<!DOCTYPE html>

<html>

<head>

</head>

<body>

<script language = "javascript" type = "text/javascript">

var number = 1

while (number<=10)

document.write("NUMBER = " + number + "<br>")


number++

document.write ("GET OUT OF THE LOOP WHEN NUMBER IS = " + number)

</script>

</body>

</html>

EX8.PROGRAM USING IF AND ELSE:

<html>

<head>

<title> my web page</title>

</head>

<body background="1.jpg">

<font color="white">

<script>

var a =prompt("ENTER AGE:");

if (a<=18)

document.write("You cannot drive","<br>");

else

document.write("You Can Drive",);

</script>

</font>

</body>
</html>

EX9.PROGRAM ON SIMPLE INTEREST:

<html>

<head>

<title> my web page</title>

</head>

<body>

<font color="BLUE">

<script>

var a =parseInt(prompt("ENTER PRINCIPAL:"));

var b =prompt("ENTER RATE OF INTEREST");

var c =prompt("ENTER YEAR:");

var d =parseInt(a*b*c)*0.01;

var e=parseInt(a+d);

document.write("THE PRINCIPAL IS :", a,"<br>")

document.write("THE RATE OF INTEREST IS :", b,"<br>")

document.write("THE YEAR IS :", c,"<br>")

document.write("THE SI IS: ", d,"<br>")

document.write("THE AMOUNT IS: ", e,"<br>")

</script>

</font>

</body>

</html>

EX10.PROGRAM ON IF AND ELSE BY GIVING INPUTS:

<html>
<head>

<title> my web page</title>

</head>

<body background="1.jpg">

<font color="white">

<script>

var a =prompt("ENTER NUMBER 1:");

var b =prompt("ENTER NUMBER 2:");

if (a>b)

document.write("a is greater than b","<br>");

else

document.write("a is less than b",);

</script>

</font>

</body>

</html>

EX11.PROGRAM SHOWING RESULT:

<html>

<head>

<title> my web page</title>

</head>

<body>
<font color="BLUE">

<script>

var a =parseInt(prompt("ENTER CCA MARKS:"));

var b =parseInt(prompt("ENTER TALLY MARKS:"));

var c =parseInt(prompt("ENETR DIA MARKS:"));

var d =parseInt(a+b+c);

var avg=parseFloat(d/3);

document.write("THE CCA MARKS IS :", a,"<br>")

document.write("THE TALLY MARKS IS :", b,"<br>")

document.write("THE DIA MARKS :", c,"<br>")

document.write("THE TOTAL MARKS IS: ", d,"<br>")

document.write("THE AVERAGE MARKS IS: ", avg,"<br>")

if(avg>95) {

alert("THE GRADE IS A");

else if(avg>=85) {

alert("THE GRADE IS B");

else if(avg>=70) {

alert("THE GRADE IS C");

else if(avg>=60) {

alert("THE GRADE IS D");

else if(avg>=50) {

alert("THE GRADE IS E");

}
else {

alert("FAIL");

</script>

</font>

</body>

</html>

EX12.PROGRAM USING FOR LOOP BY TAKING INPUTS:

<html>

<head>

<title> my web page</title>

</head>

<body background="1.jpg">

<font color="white">

<script>

var a =prompt("ENTER NAME:");

document.write(a,"<br>");

for (var i=0;i<=100;i++)

document.write(a,"<br>")

</script>

</font>

</body>

</html>
EX13.PROGRAM USING FOR LOOP:

<html>

<head>

<title> my web page</title>

</head>

<body background="1.jpg">

<font color="white">

<script>

var i;

document.write("THE FIRST 100 NATURAL NUMBERS","<br>")

for (var i=0;i<=100;i++)

document.write(i,"<br>")

</script>

</font>

</body>

</html>

EX14.PROGRAM ON INFINITE LOOP:

<html>

<head>

<title> my web page</title>

</head>

<body background="1.jpg">

<font color="white">

<script>
var i;

document.write("THE FIRST 100 NATURAL NUMBERS","<br>")

for (var i=1;i>0;i++)

document.write(i,"<br>")

</script>

</font>

</body>

</html>

EX15.PROGRAM ON LEAP YEAR:

<html>

<head>

<title> my web page</title>

</head>

<body background="1.jpg">

<font color="white">

<script>

var a =prompt("ENTER year:");

a= (a%4);

if(a==0)

document.write("The Year is a leap Year","<br>");

else

{
document.write("The Year is not a leap Year",);

</script>

</font>

</body>

</html>

You might also like