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

VandanaGaria Assignment - 3

This document describes an HTML form and JavaScript code to perform calculations on a user-entered number. The form includes a number input field and buttons to calculate the factorial, check if prime, sum of digits, and product of digits of the number. The JavaScript code defines functions for each calculation that output the result in the "res" form field.

Uploaded by

Vandana Garia
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)
29 views4 pages

VandanaGaria Assignment - 3

This document describes an HTML form and JavaScript code to perform calculations on a user-entered number. The form includes a number input field and buttons to calculate the factorial, check if prime, sum of digits, and product of digits of the number. The JavaScript code defines functions for each calculation that output the result in the "res" form field.

Uploaded by

Vandana Garia
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

Full Stack Development Assignment - 3

Ques: Design the following HTML form and write Javascript code to perform following
operations.

Code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,
initial-scale=1.0">
<title>Document1</title>
<style>

input{
width: 110px;
height: 25px;

}
button{
width: 120px;
height: 20px;
top:50%;
background-color:#7ca6b9;
}

</style>
<script lang = "Javascript">
function f1()
{
var fac = 1;
var num = frm.f.value;
var i;
for(i=1;i<=num;i++)
{
fac = fac*i;
}
frm.res.value = fac;
}
function f2()
{
var n,i,flag = true;
n = parseInt(frm.f.value);

for(i=2;i<=n-1;i++)
if(n%i==0)
{
flag = false;
break;
}

if(flag==true)
{
frm.res.value = "Yes";
}

else{
frm.res.value = "NA";
}
}

function f3()
{
var sum = 0;
var num = frm.f.value;
while(num>0){
sum = sum+num%10;
num = parseInt(num/10);
}
frm.res.value = sum;
}

function f4()
{
var prod = 1;
var num = frm.f.value;
while(num>0){
prod = prod*(num%10);
num = parseInt(num/10);
}
frm.res.value = prod;
}
</script>
</head>
<body>
<div style="text-align: center;" >
<form name = "frm">
<center><table class="tb">
<tr>
<td > Enter the Number:</td>
<td><input name="f" size="5" type="text"></td>
</tr>
</table>

<table>
<tr>
<td><button type="button" onclick="f1()" >Find
Factorial</td>
<td><button type="button" onclick="f2()" >Check
Prime</td>
<td><button type="button" onclick="f3()" >Sum of
digits</td>
<td><button type="button" onclick="f4()" >Product
of digits</td>

<td><button type="reset" style="height:20px;

width:50px" >Clear</button></td>
</tr>

</table>

<table>
<tr>
<td>Result: </td>
<td><input name="res" size="5" type="text"></td>
</tr>
</table>
</center>

</form>
</div>
</body>
</html>
Outputs:

1. Find Factorial

2. Check Prime Number

3. Sum of the Digits

4. Product of Digits

You might also like