0% found this document useful (0 votes)
455 views3 pages

Write A Program To Calculate Percentage of Given Marks

The document contains 3 JavaScript programs using functions: 1) A function to calculate the percentage of total marks obtained in 5 subjects. 2) A function to display prime numbers within a given range by checking if each number is divisible only by 1 and itself. 3) Functions to perform push and pop operations on a stack data structure, implemented with an array, to add and remove elements.

Uploaded by

sakshi
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)
455 views3 pages

Write A Program To Calculate Percentage of Given Marks

The document contains 3 JavaScript programs using functions: 1) A function to calculate the percentage of total marks obtained in 5 subjects. 2) A function to display prime numbers within a given range by checking if each number is divisible only by 1 and itself. 3) Functions to perform push and pop operations on a stack data structure, implemented with an array, to add and remove elements.

Uploaded by

sakshi
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/ 3

Practical 4

/* 1. Write a program to calculate percentage of given marks */

<html>
<body>
<script lang="Javascript" type="text/javascript">
function marks(a, b, c, d, e)
{ var t = a + b + c + d + e;
document.write("<br><br><b> Total of marks =</b> "
+ t);
var percent = t * 100 / 750;
document.write("<br><br><b> Percentage =</b> " +
percent);
}
document.write("<b>MARKS OBTAINED IN SUBJECTS:
</b><br>");
var a = Number(document.write("<br>OOP = 132"));
var b = Number(document.write("<br>DSU = 141"));
var c = Number(document.write("<br>CGR = 137"));
var d = Number(document.write("<br>DBMS = 141"));
var e = Number(document.write("<br>DTE = 141"));
marks(132, 141, 137, 141, 141);
</script>
</body>
</html>

/* 2.Write a program to display prime numbers using function */

<html>
<body>
<script lang="Javascript" type="text/javascript">
function Prime()
{ var a = Number(prompt("Enter starting number for
range"));
var b = Number(prompt("Enter ending number for
range"));
document.write('<b>Prime numbers between ' + a, '
and ' + b, " :</b>");
var num = a;
Practical 4

while (num <= b)


{ var c = 0;
var i = 2;
while (i <= num / 2)
{ if (num % i == 0)
{
c++;
break;
}
i++;
}
if (c == 0 && num != 1)
{
document.write("<br>" + num);
}
num++;
}
}
Prime();
</script>
</body>
</html>

/* 3. Write a program to perform stack operations of push and


pop using function */

<html>
<body>
<script lang="Javascript" type="text/javascript">
function Push()
{ document.write('<br><br><b>USING PUSH( )</b>');
languages.push("<b>Advanced Java</b>");
document.write("<br><b> Elements after push :
</b><br>");
for (var i = 0; i < languages.length; i++)
{
document.write(languages[i] + "<br>");
}
}
Practical 4

function Pop()
{ document.write('<br><br><b>USING POP( )</b>');
languages.pop();
document.write("<br><b> Elements after pop :
</b><br>");
for (var i = 0; i < languages.length; i++)
{
document.write(languages[i] + "<br>");

}
}
var languages = ["C", "C++", "HTML", "CSS", "Java",
"VB"];
document.write("<b>Elements : </b><br>");
//LOOPING
for (let i = 0; i < languages.length; i++)
{
document.write(languages[i] + '<br>')
}

Push();

Pop();
</script>
</body>
</html>

You might also like