Untitled 1
Untitled 1
code to
accept the
Principal
Amount, rate
and time
from the
user.
Calculate and display
SI=PA*R*T
CI=PA*(1+R/100)Time
Code-
<script>
pa=parseInt(prompt("Enter pa:"))
r=parseInt(prompt("Enter r:"))
t=parseInt(prompt("Enter t:"))
Simpleinterest=pa*r*t
compoundinterest=Math.pow(1+r/100,t)
document.write("si="+Simpleinterest+"<br>")
document.write("ci="+compoundinterest)
</script>
Output-
Code-
<script>
if(num%2==0)
document.write("even")
else
document.write("odd")
</script>
Output-
3 Write JS code to accept a number and check whether it is positive, negative or zero
Code-
<script>
if(num>0)
document.write("positive")
else if(num<0)
document.write("negative")
else
document.write("zero")
</script>
Output-
4 Write JS code to accept the total mark of a student and display the grade as per the
following table.
TOTAL GRADE
>=90 A
>=80 B
>=70 C
>=60 D
<60 F
Code-
<script>
if(TotalMarks>=90)
document.write("A")
else if(TotalMarks>=80)
document.write("B")
else if(TotalMarks>=70)
document.write("C")
else if(TotalMarks>=60)
document.write("D")
else
document.write("F")
</script>
Output-
5 Write JS code to accept the index of the month and display the month name using switch.
Code-
<script>
switch(Month)
case 1:
document.write("january");
break;
case 2:
document.write("February")
break;
case 3:
document.write("March");
break;
case 4:
document.write("April");
break;
case 5:
document.write("May");
break;
case 6:
document.write("June");
break;
case 7:
document.write("july");
break;
case 8:
document.write("august");
break;
case 9:
document.write("september");
break;
case 10:
document.write("october");
break;
case 11:
document.write("november");
break;
case 12:
document.write("december");
break;
default:
document.write("invalid");
break;
</script>
Output-
6Write JS code to display the first 15 natural numbers and their sum.
Code-
<script>
sum=0
for(i=0;i<=15;i++)
sum=sum+i
</script>
Output-
7accet a number from the user and display its multiplication table on the browser window.
Code-
<script>
num=parseInt(prompt("Enter A Number:"))
for(i=0;i<=10;i++)
document.write(num+"x"+i+"="+num*i+"<br>")
</script>
Output-
##
###
####
Code-
<script>
for(i=1;i<=4;i++)
for(j=1;j<=i;j++)
document.write("#")
}
document.write("<br>")
</script>
Output-
9 Create the following html form. Write JS code to perform the arithmetic operations on clicking the
Code-
<html>
<script>
function add()
n1=parseInt(document.form1.txt1.value)
n2=parseInt(document.form1.txt2.value)
document.form1.txt3.value=n1+n2
function sub()
n1=parseInt(document.form1.txt1.value)
n2=parseInt(document.form1.txt2.value)
document.form1.txt3.value=n1-n2
function mul()
{
n1=parseInt(document.form1.txt1.value)
n2=parseInt(document.form1.txt2.value)
document.form1.txt3.value=n1*n2
function div()
n1=parseInt(document.form1.txt1.value)
n2=parseInt(document.form1.txt2.value)
document.form1.txt3.value=n1/n2
function mod()
n1=parseInt(document.form1.txt1.value)
n2=parseInt(document.form1.txt2.value)
document.form1.txt3.value=n1%n2
</script>
<body>
<form name=form1>
<br> <br>
<br><br>
</form>
</body>
</html>
Output-
10) Create the following html form. Write JS code to perform the numeric operations on clicking the
Code-
<html>
<script>
function sumofdigits()
n1=parseInt(document.form1.txt1.value)
sum=0
while(n1>0)
rem=n1%10
sum=sum+rem
n1=parseInt(n1/10)
document.form1.txt3.value=sum
function productofdigits()
n1=parseInt(document.form1.txt1.value)
pro=1
while(n1>0)
rem=n1%10
pro
=pro*rem
n1=parseInt(n1/10)
document.form1.txt3.value=pro
function sumofalternatedigits()
n1=parseInt(document.form1.txt1.value)
sum=0
while(n1>0)
rem=n1%10
sum=sum+rem
n1=parseInt(n1/100)
document.form1.txt3.value=sum
}
function reverseofdigits()
n1=parseInt(document.form1.txt1.value)
rev=0
while(n1>0)
rem=n1%10
rev=rev*10+rem
n1=parseInt(n1/10)
document.form1.txt3.value=rev
function prime()
n1=parseInt(document.form1.txt1.value)
flag=0
for(i=2;i<n1;i++)
if(n1%i==0)
flag=1;
break;
if(flag==0)
document.form1.txt3.value="prime"
else
document.form1.txt3.value="composite"
}
</script>
<body>
<form name=form1>
<br> <br>
<br><br>
</form>
</body>
</html>
Output-