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

Function PR4

The document presents a practical assignment to develop JavaScript programs that implement functions for checking even/odd numbers, finding prime numbers, and performing stack operations (push and pop). Each code snippet includes HTML and JavaScript to execute the respective functionalities. The output sections are left blank, indicating that the results of the operations are expected to be displayed in the browser.

Uploaded by

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

Function PR4

The document presents a practical assignment to develop JavaScript programs that implement functions for checking even/odd numbers, finding prime numbers, and performing stack operations (push and pop). Each code snippet includes HTML and JavaScript to execute the respective functionalities. The output sections are left blank, indicating that the results of the operations are expected to be displayed in the browser.

Uploaded by

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

Practical No 04

Title: Develop a JavaScript program to implement Function.


Sub : CSS
Batch : B
Roll No : 26
Code 1:
<html>
<head></head>
<script>
function evenodd()
{
for(var i=0;i<=20;i++)
{
if(i%2==0)
document.write("<br>"+i+" is Even number"+"</b>");
else
document.writeln("<br>"+i+" is odd number");
}
}
</script>
<input type="button" onclick="evenodd()" value="Check Even/Odd No..!"/>
</html>
Output:

Code 2:
<html>
<head></head>
<script>
function prime()
{
document.write(“<b>” + "Prime Numbers <br>" + “</b>”);
let i,n,flag;

for(no=2;no<100;no++)
{
i=2;
flag=0;
while(i<no)
{
if(no%i==0)
{
flag=1;
break;
}
i++;
}
if(flag==0)
document.write(“<b>” + "&nbsp"+no + “</b>”);
}
}
prime();
</script>
</html>
Output:

Code 3:
<html>
<head></head>
<script>
var num;
var stack=[15,89,55,90,21,9,73,10];
document.write("<br>"+"Which operation do you want to perform on stack : ");
function pushOp()
{
num=prompt("Enter element you want to insert :- ");
stack.push(num);
document.write("<b>" + "<br>"+"Array Elements are : " + "</b>");
for(var i=0;i<stack.length;i++)
{
document.write("<b>" + "<br>"+stack[i] + "</b>");
}
}
function popOp()
{
stack.pop();
document.write("<b>" + "<br>"+"Array Elements are: " + "</b>");
for(var i=0;i<stack.length;i++)
{
document.write("<b>" + "<br>"+stack[i] + "</b>");
}
}
</script>
<input type="button" onclick="pushOp()" value= "Push"/>
<input type="button" onclick="popOp()" value= "Pop"/>
</html>
Output:
Push :-
Pop :-

You might also like