Function PR4
Function PR4
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>” + " "+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 :-