0% found this document useful (0 votes)
2 views4 pages

Practical 2

The document contains three JavaScript programs: one to display even and odd numbers from 0 to 10, another to display prime numbers up to 100, and a third that prompts the user to change the background color of the webpage. Each program includes HTML structure and JavaScript code for functionality. The output of each program is indicated but not explicitly shown in the document.

Uploaded by

mayankshinde0116
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)
2 views4 pages

Practical 2

The document contains three JavaScript programs: one to display even and odd numbers from 0 to 10, another to display prime numbers up to 100, and a third that prompts the user to change the background color of the webpage. Each program includes HTML structure and JavaScript code for functionality. The output of each program is indicated but not explicitly shown in the document.

Uploaded by

mayankshinde0116
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/ 4

Practical 2

Q1 write a program to display even odd numbers


Code:
<html>
<body>
<script type="text/javascript">
//q1)print even odd numbers
var a=1;
for(a=0;a<=10;a++)
{
if(a%2==0)
{
document.write("<br>even number: "+a);
}
else
{
document.write("<br>odd number: "+a);
}
}
</script>
</body>
</html>
Output:
Q2 write a program to display prime number
Code:
<html>
<body>
<script type="text/javascript">
//q2)prime numbers
var count=0
var i,j
for(j=2;j<=100;j++)
{
for( i=1;i<=j;i++)
{
if(j%i==0)
{
count++
}
}
if(count==2)
document.write("<br>"+j)
count=0
}
</script>
</body>
</html>
Output:
Q3 write a program to ask user wether he want to change background color
Code:
<html>
<body>
<script type="text/javascript">
//q.3)is colour change
var ch=prompt("is you want to change color? ");
if(ch=="yes")
{
var col=prompt("enter which color you want? ");
document.body.style.backgroundColor =col;
}
else
{
alert("you deneyed to change color");
}
</script>
</body>
</html>
Output:

You might also like